log using log_merge.log, replace
clear all
**Set working directory to location of files**
*cd "location"

*********************************************************************************
*** Prepare for merge by providing V-Dem ID's (V-Dem Codebook 11.1, p. 39-40) *** 
*********************************************************************************


*********************************************************
**************** Lexical Index 6.0 **********************
*********************************************************

use "Lexical Index v6.0.dta" 

* rename country_id variable
rename vdem country_id
rename countryn country_name

* No V-dem id for following, Greenland added manually
replace country_id = 1081 if country_name=="Newfoundland"
replace country_id = 11384 if country_name=="Cape Colony"
replace country_id = 113818 if country_name=="Transvaal"
replace country_id = 113812 if country_name=="Natal"
replace country_id = 113814 if country_name=="Orange Free State"
replace country_id = 1145 if country_name=="Sahrawi"
replace country_id = 9999 if country_name=="Tibet"
replace country_id = 9998 if country_name=="Greenland"

save "Lexical Index v6.0 for merge.dta"




*********************************************************
**************** Fariss et al. GDP pc. ******************
*********************************************************

use "Fariss et al - estimates_all_long_210911.dta"

generate country_id = .
order country_id, after(gwno)


*"Afghanistan"
replace country_id = 36 if gwno==700

*"Albania"
replace country_id = 12 if gwno==339

*"Algeria"
replace country_id = 103 if gwno==615

*"Angola"
replace country_id = 104 if gwno==540

*"Argentina"
replace country_id = 37 if gwno==160

*"Armenia"
replace country_id = 105 if gwno==371

*"Australia"
replace country_id = 67 if gwno==900

*"Austria"
replace country_id = 144 if gwno==305

*"Austria-Hungary"
replace country_id = 144 if gwno==300

*"Azerbaijan"
replace country_id = 106 if gwno==373

*"Bahrain"
replace country_id = 146 if gwno==692

*"Bangladesh"
replace country_id = 24 if gwno==771

*"Barbados"
replace country_id = 147 if gwno==53

*"Belarus"
replace country_id = 107 if gwno==370

*"Belgium"
replace country_id = 148 if gwno==211

*"Benin"
replace country_id = 52 if gwno==434

*"Bhutan"
replace country_id = 53 if gwno==760

*"Bolivia"
replace country_id = 25 if gwno==145

*Herzegovina"
replace country_id = 150 if gwno==346

*"Botswana"
replace country_id = 68 if gwno==571

*"Brazil"
replace country_id = 19 if gwno==140

*"Bulgaria"
replace country_id = 152 if gwno==355

*"Burkina Faso"
replace country_id = 54 if gwno==439

*"Myanmar"
replace country_id = 10 if gwno==775

*"Burundi"
replace country_id = 69 if gwno==516

*"Cambodia"
replace country_id = 55 if gwno==811

*"Cameroon"
replace country_id = 108 if gwno==471

*"Canada"
replace country_id = 66 if gwno==20

*"Cape Verde"
replace country_id = 70 if gwno==402

*"Central African Republic"
replace country_id = 71 if gwno==482

*"Chad"
replace country_id = 109 if gwno==483

*"Chile"
replace country_id = 72 if gwno==155

*"China"
replace country_id = 110 if gwno==710

*"Colombia"
replace country_id = 15 if gwno==100

*"Comoros"
replace country_id = 153 if gwno==581

*"Republic of Congo"
replace country_id = 112 if gwno==484

*"Democratic Republic of the Congo"
replace country_id = 111 if gwno==490

*"Costa Rica"
replace country_id = 73 if gwno==94

*"Croatia"
replace country_id = 154 if gwno==344

*"Cuba"
replace country_id = 155 if gwno==40

*"Cyprus"
replace country_id = 156 if gwno==352

*"Czech Republic"
replace country_id = 157 if gwno==316

*"Czechoslovakia"
replace country_id = 157 if gwno==315

*"Denmark"
replace country_id = 158 if gwno==390

*"Djibouti"
replace country_id = 113 if gwno==522

*"Dominican Republic"
replace country_id = 114 if gwno==42

*"Ecuador"
replace country_id = 75 if gwno==130

*"Egypt"
replace country_id = 13 if gwno==651

*"El Salvador"
replace country_id = 22 if gwno==92

*"Equatorial Guinea"
replace country_id = 160 if gwno==411

*"Eritrea"
replace country_id = 115 if gwno==531

*"Estonia"
replace country_id = 161 if gwno==366

*"Ethiopia"
replace country_id = 38 if gwno==530

*"Fiji"
replace country_id = 162 if gwno==950

*"Finland"
replace country_id = 163 if gwno==375

*"France"
replace country_id = 76 if gwno==220

*"Gabon"
replace country_id = 116 if gwno==481

*"Georgia"
replace country_id = 118 if gwno==372

*"Germany"
replace country_id = 77 if gwno==260

*"West Germany"
replace country_id = 77 if gwno==260

*"Germany (Prussia)"
replace country_id = 77 if gwno== 255

*"German Federal Republic"
replace country_id = 77 if gwno==260

*"German Democratic Republic"
replace country_id = 137 if gwno==265

*"Hanover"
replace country_id = 357 if gwno==240

*"Bavaria"
replace country_id = 350 if gwno==245

*"Baden"
replace country_id = 349 if gwno==267

*"Saxony"
replace country_id = 353 if gwno==269

*"WÙrttemberg"
replace country_id = 355 if gwno==271

*"Hesse-Kassel (Electoral)"
replace country_id = 358 if gwno==273

*"Hesse-Darmstadt (Ducal)"
replace country_id = 359 if gwno==275

*"Mecklenburg-Schwerin"
replace country_id = 360 if gwno==280

*"Ghana"
replace country_id = 7 if gwno==452

*"Greece"
replace country_id = 164 if gwno==350

*"Guatemala"
replace country_id = 78 if gwno==90

*"Guinea"
replace country_id = 63 if gwno==438

*"Guinea Bissau"
replace country_id = 119 if gwno==404

*"Guyana"
replace country_id = 166 if gwno==110

*"Haiti"
replace country_id = 26 if gwno==41

*"Honduras"
replace country_id = 27 if gwno==91

*"Hungary"
replace country_id = 210 if gwno==310

*"Iceland"
replace country_id = 168 if gwno==395

*"India"
replace country_id = 39 if gwno==750

*"Indonesia"
replace country_id = 56 if gwno==850

*"Iran"
replace country_id = 79 if gwno==630

*"Iraq"
replace country_id = 80 if gwno==645

*"Ireland"
replace country_id = 81 if gwno==205

*"Israel"
replace country_id = 169 if gwno==666

*"Italy"
replace country_id = 82 if gwno==325

*"Papal States"
replace country_id = 361 if gwno==327

*"Two Sicilies"
replace country_id = 356 if gwno==329

*"Modena"
replace country_id = 351 if gwno==332

*"Parma"
replace country_id = 352 if gwno==335

*"Tuscany"
replace country_id = 354 if gwno==337

*"Cote D'Ivoire"
replace country_id = 64 if gwno==437

*"Jamaica"
replace country_id = 120 if gwno==51

*"Japan"
replace country_id = 9 if gwno==740

*"Jordan"
replace country_id = 83 if gwno==663

*"Kazakhstan"
replace country_id = 121 if gwno==705

*"Kenya"
replace country_id = 40 if gwno==501

*"Kosovo"
replace country_id = 43 if gwno==347

*"Kuwait"
replace country_id = 171 if gwno==690

*"Kyrgyzstan"
replace country_id = 122 if gwno==703

*"Laos"
replace country_id = 123 if gwno==812

*"Latvia"
replace country_id = 84 if gwno==367

*"Lebanon"
replace country_id = 44 if gwno==660

*"Lesotho"
replace country_id = 85 if gwno==570

*"Liberia"
replace country_id = 86 if gwno==450

*"Libya"
replace country_id = 124 if gwno==620

*r"Lithuania"
replace country_id = 173 if gwno==368

*"Luxembourg"
replace country_id = 174 if gwno==212

*"Macedonia"
replace country_id = 176 if gwno==343

*"Madagascar"
replace country_id = 125 if gwno==580

*"Malawi"
replace country_id = 87 if gwno==553

*"Malaysia"
replace country_id = 177 if gwno==820

*"Maldives"
replace country_id = 88 if gwno==781

*"Mali"
replace country_id = 28 if gwno==432

*"Mauretania"
replace country_id = 65 if gwno==435

*"Mauritius"
replace country_id = 180 if gwno==590

*"Mexico"
replace country_id = 3 if gwno==70

*"Moldova"
replace country_id = 126 if gwno==359

*"Mongolia"
replace country_id = 89 if gwno==712

*"Montenegro"
replace country_id = 183 if gwno== 341

*"Morocco"
replace country_id = 90 if gwno==600

*"Mozambique"
replace country_id = 57 if gwno==541

*"Nambibia"
replace country_id = 127 if gwno==565

*"Nepal"
replace country_id = 58 if gwno==790

*"Netherlands"
replace country_id = 91 if gwno==210

*"New Zealand"
replace country_id = 185 if gwno==920

*"Nicaragua"
replace country_id = 59 if gwno==93

*"Niger"
replace country_id = 60 if gwno==436

*"Nigeria"
replace country_id = 45 if gwno==475

*"Norway"
replace country_id = 186 if gwno==385

*"Oman"
replace country_id = 187 if gwno==698

*"Pakistan"
replace country_id = 29 if gwno==770

*"Panama"
replace country_id = 92 if gwno==95

*"Papua New Guinea"
replace country_id = 93 if gwno==910

*"Paraguay"
replace country_id = 189 if gwno==150

*"Peru"
replace country_id = 30 if gwno==135

*"Philippines"
replace country_id = 46 if gwno==840

*"Poland"
replace country_id = 17 if gwno==290

*"Portugal"
replace country_id = 21 if gwno==235

*"Qatar"
replace country_id = 94 if gwno==694

*"Romania"
replace country_id = 190 if gwno==360

*"Russia"
replace country_id = 11 if gwno==365

*"Rwanda"
replace country_id = 129 if gwno==517

*"Saudi Arabia"
replace country_id = 197 if gwno==670

*"Senegal"
replace country_id = 31 if gwno==433

*"Serbia"
replace country_id = 198 if gwno==340

*"Yugoslavia"
replace country_id = 198 if gwno==345

*"Seychelles"
replace country_id = 199 if gwno==591

*"Sierra Leone"
replace country_id = 95 if gwno==451

*"Singapore"
replace country_id = 200 if gwno==830

*"Slovakia"
replace country_id = 201 if gwno==317

*"Slovenia"
replace country_id = 202 if gwno==349

*"Somalia"
replace country_id = 130 if gwno==520

*"South Africa"
replace country_id = 8 if gwno==560

*"Spain"
replace country_id = 96 if gwno==230

*"Sri Lanka"
replace country_id = 131 if gwno==780

*"Sudan"
replace country_id = 33 if gwno==625

*"Suriname"
replace country_id = 4 if gwno==115

*"Swaziland"
replace country_id = 132 if gwno==572

*"Sweden"
replace country_id = 5 if gwno==380

*"Switzerland"
replace country_id = 6 if gwno==225

*"Syria"
replace country_id = 97 if gwno==652

*"Taiwan"
replace country_id = 48 if gwno==713

*"Tajikistan"
replace country_id = 133 if gwno==702

*"Tanzania"
replace country_id = 47 if gwno==510

*"Thailand"
replace country_id = 49 if gwno==800

*"The Gambia"
replace country_id = 117 if gwno==420

*"East Timor"
replace country_id = 74 if gwno==860

*"Togo"
replace country_id = 134 if gwno==461

*"Trinidad and Tobago"
replace country_id = 135 if gwno==52

*"Tunisia"
replace country_id = 98 if gwno==616

*"Turkey"
replace country_id = 99 if gwno==640

*"Turkmenistan"
replace country_id = 136 if gwno==701

*"Uganda"
replace country_id = 50 if gwno==500

*"Ukraine"
replace country_id = 100 if gwno==369

*"United Arab Emirates"
replace country_id = 207 if gwno==696

*"United Kingdom"
replace country_id = 101 if gwno==200

*"United States of America"
replace country_id = 20 if gwno==2

*"Uruguay"
replace country_id = 102 if gwno==165

*"Uzbekistan"
replace country_id = 140 if gwno==704

*"Vanuatu"
replace country_id = 206 if gwno==935

*"Venezuela"
replace country_id = 51 if gwno==101

*"Vietnam"
replace country_id = 34 if gwno== 816

*"Vietnam, Democratic Republic of"
replace country_id = 34 if gwno==816

*"Vietnam (Annam/Cochin China/Tonkin)"
replace country_id = 35 if gwno==815

*"Vietnam, Republic of"
replace country_id = 35 if gwno==817

*"Yemen"
replace country_id = 14 if gwno==678

*"Yemen (Arab Republic of Yemen)"
replace country_id = 14 if gwno==678

*"Yemen, People's Republic of"
replace country_id = 23 if gwno==680

*"Zambia"
replace country_id = 61 if gwno==551

*"Zimbabwe"
replace country_id = 62 if gwno==552

*"Namibia"
replace country_id = 127 if gwno==565

*"Korea"
replace country_id = 42 if gwno==730

*"Korea, Republic of"
replace country_id = 42 if gwno==732

*"Korea, People's Republic of"
replace country_id = 41 if gwno==731

*"Solomon Islands"
replace country_id = 203 if gwno==940

*"Zanzibar"
replace country_id = 236 if gwno==511

*"South Sudan"
replace country_id = 32 if gwno==626

*"Malta"
replace country_id = 178 if gwno==338

*"Brunei"
replace country_id = 151 if gwno==835

*"The Bahamas"
replace country_id = 145 if gwno==31

*"Belize"
replace country_id = 149 if gwno==80

*"Bahamas"
replace country_id = 145 if gwno==31

*"Sao Tome and Principe"
replace country_id = 196 if gwno==403

*"Transvaal"
replace country_id = 113818 if gwno==563

*"Orange Free State"
replace country_id = 113814 if gwno==564

*"Tibet"
replace country_id = 9999 if gwno==711

*"Great Colombia"
replace country_id = 15 if gwno==99

*"Samoa/Western Samoa"
replace country_id = 194 if gwno==990

*"Saint Kitts and Nevis"
replace country_id = 191 if gwno==60

*"Palau"
replace country_id = 188 if gwno==986

*"United Provinces of Central America"
replace country_id = 78 if gwno==89

*"Kiribati"
replace country_id = 170 if gwno==970

*"Nauru"
replace country_id = 184 if gwno==971

*"Tonga"
replace country_id = 204 if gwno==972

*"Tuvalu"
replace country_id = 205 if gwno==973

*"Marshall Islands"
replace country_id = 179 if gwno==983

*"Federated States of Micronesia"
replace country_id = 181 if gwno==987

*"Dominica"
replace country_id = 159 if gwno==54

*"Grenada"
replace country_id = 165 if gwno==55

*"Saint	 Lucia"
replace country_id = 192 if gwno==56

*"Saint Vincent and the Grenadines"
replace country_id = 193 if gwno==57

*"Antigua & Barbuda"
replace country_id = 143 if gwno==58

*"Monaco"
replace country_id = 182 if gwno==221

*"Liechtenstein"
replace country_id = 172 if gwno==223

*"Andorra"
replace country_id = 142 if gwno==232

*"San Marino"
replace country_id = 195 if gwno==331

*"Seychelles"
replace country_id = 199 if gwno==591

*** Drop Abhkazia and South Ossetia
drop if country_id==.


keep if indicator =="latent_gdppc"
keep if year >=1789

rename mean_log latent_gdppc_mean_log
rename mean latent_gdppc_mean
rename mean_log10 latent_gdppc_mean_log10
rename sd_log sd_log_latent_gdppc
rename sd sd_latent_gdppc
rename sd_log10 sd_log10_latent_gdppc
drop group og_log og_log10 og indicator

*** Search for dupliates in terms of year and V-Dem ID

duplicates tag country_id year, gen(tag)

* Serbia corresponds to Yugoslavia in V-Dem dataset. Drop observations for Serbia, so Serbia receives values for Yugoslavia in line with V-Dem coding
drop if gwno ==340 & year <=2006 & year >=1918

* drop Austria-Hungary
drop if gwno ==300

* Drop United Provinces of Central America
drop if gwno == 89

* Drop Great Colombia
drop if gwno == 99

drop tag

save "Fariss et al. latent_gdp_pc with V-Dem_id for merge.dta"



***************************************************
*********************** Houle 2015 ****************
***************************************************
use "Houle 2015 - Country Data.dta" 

generate country_id = .
order country_id, after(country)
replace country_id = 36 if country=="Afghanistan"
replace country_id = 12 if country=="Albania"
replace country_id = 103 if country=="Algeria"
replace country_id = 104 if country=="Angola"
replace country_id = 37 if country=="Argentina"
replace country_id = 105 if country=="Armenia"
replace country_id = 67 if country=="Australia"
replace country_id = 144 if country=="Austria"
replace country_id = 106 if country=="Azerbaijan"
replace country_id = 146 if country=="Bahrain"
replace country_id = 24 if country=="Bangladesh"
replace country_id = 147 if country=="Barbados"
replace country_id = 107 if country=="Belarus"
replace country_id = 148 if country=="Belgium"
replace country_id = 52 if country=="Benin"
replace country_id = 53 if country=="Bhutan"
replace country_id = 25 if country=="Bolivia"
replace country_id = 150 if country=="Bosnia and Herzegovina"
replace country_id = 68 if country=="Botswana"
replace country_id = 19 if country=="Brazil"
replace country_id = 152 if country=="Bulgaria"
replace country_id = 54 if country=="Burkina Faso"
replace country_id = 10 if country=="Myanmar"
replace country_id = 69 if country=="Burundi"
replace country_id = 55 if country=="Cambodia"
replace country_id = 108 if country=="Cameroon"
replace country_id = 66 if country=="Canada"
replace country_id = 70 if country=="Cape Verde"
replace country_id = 71 if country=="Central African Republic"
replace country_id = 71 if country=="CAR"
replace country_id = 109 if country=="Chad"
replace country_id = 72 if country=="Chile"
replace country_id = 110 if country=="China"
replace country_id = 15 if country=="Colombia"
replace country_id = 153 if country=="Comoros"
replace country_id = 112 if country=="Congo"
replace country_id = 111 if country=="Democratic Republic of the Congo"
replace country_id = 73 if country=="Costa Rica"
replace country_id = 154 if country=="Croatia"
replace country_id = 155 if country=="Cuba"
replace country_id = 156 if country=="Cyprus"
replace country_id = 157 if country=="Czech Republic"
replace country_id = 157 if country=="Czechoslovakia"
replace country_id = 158 if country=="Denmark"
replace country_id = 113 if country=="Djibouti"
replace country_id = 114 if country=="Dominican Republic"
replace country_id = 75 if country=="Ecuador"
replace country_id = 13 if country=="Egypt"
replace country_id = 22 if country=="El Salvador"
replace country_id = 160 if country=="Equatorial Guinea"
replace country_id = 115 if country=="Eritrea"
replace country_id = 161 if country=="Estonia"
replace country_id = 38 if country=="Ethiopia"
replace country_id = 162 if country=="Fiji"
replace country_id = 163 if country=="Finland"
replace country_id = 76 if country=="France"
replace country_id = 116 if country=="Gabon"
replace country_id = 118 if country=="Georgia"
replace country_id = 77 if country=="Germany"
replace country_id = 7 if country=="Ghana"
replace country_id = 164 if country=="Greece"
replace country_id = 78 if country=="Guatemala"
replace country_id = 63 if country=="Guinea"
replace country_id = 119 if country=="Guinea-Bissau"
replace country_id = 166 if country=="Guyana"
replace country_id = 26 if country=="Haiti"
replace country_id = 27 if country=="Honduras"
replace country_id = 167 if country=="Hong Kong"
replace country_id = 210 if country=="Hungary"
replace country_id = 168 if country=="Iceland"
replace country_id = 39 if country=="India"
replace country_id = 56 if country=="Indonesia"
replace country_id = 79 if country=="Iran"
replace country_id = 80 if country=="Iraq"
replace country_id = 81 if country=="Ireland"
replace country_id = 169 if country=="Israel"
replace country_id = 82 if country=="Italy"
replace country_id = 64 if country=="Ivory Coast"
replace country_id = 120 if country=="Jamaica"
replace country_id = 9 if country=="Japan"
replace country_id = 83 if country=="Jordan"
replace country_id = 121 if country=="Kazakhstan"
replace country_id = 40 if country=="Kenya"
replace country_id = 43 if country=="Kosovo"
replace country_id = 171 if country=="Kuwait"
replace country_id = 122 if country=="Kyrgyzstan"
replace country_id = 123 if country=="Laos"
replace country_id = 84 if country=="Latvia"
replace country_id = 44 if country=="Lebanon"
replace country_id = 85 if country=="Lesotho"
replace country_id = 86 if country=="Liberia"
replace country_id = 124 if country=="Libya"
replace country_id = 173 if country=="Lithuania"
replace country_id = 174 if country=="Luxembourg"
replace country_id = 176 if country=="Macedonia"
replace country_id = 125 if country=="Madagascar"
replace country_id = 87 if country=="Malawi"
replace country_id = 177 if country=="Malaysia"
replace country_id = 88 if country=="Maldives"
replace country_id = 28 if country=="Mali"
replace country_id = 65 if country=="Mauretania"
replace country_id = 65 if country=="Mauritania"
replace country_id = 180 if country=="Mauritius"
replace country_id = 3 if country=="Mexico"
replace country_id = 126 if country=="Moldova"
replace country_id = 89 if country=="Mongolia"
replace country_id = 183 if country=="Montenegro"
replace country_id = 90 if country=="Morocco"
replace country_id = 57 if country=="Mozambique"
replace country_id = 127 if country=="Nambibia"
replace country_id = 58 if country=="Nepal"
replace country_id = 91 if country=="Netherlands"
replace country_id = 185 if country=="New Zealand"
replace country_id = 59 if country=="Nicaragua"
replace country_id = 60 if country=="Niger"
replace country_id = 45 if country=="Nigeria"
replace country_id = 186 if country=="Norway"
replace country_id = 187 if country=="Oman"
replace country_id = 29 if country=="Pakistan"
replace country_id = 92 if country=="Panama"
replace country_id = 93 if country=="Papua New Guinea"
replace country_id = 189 if country=="Paraguay"
replace country_id = 30 if country=="Peru"
replace country_id = 46 if country=="Philippines"
replace country_id = 17 if country=="Poland"
replace country_id = 21 if country=="Portugal"
replace country_id = 94 if country=="Qatar"
replace country_id = 190 if country=="Romania"
replace country_id = 11 if country=="Russia"
replace country_id = 129 if country=="Rwanda"
replace country_id = 196 if country=="Sao Tome and Principe"
replace country_id = 197 if country=="Saudi Arabia"
replace country_id = 31 if country=="Senegal"
replace country_id = 198 if country=="Serbia"
replace country_id = 199 if country=="Seychelles"
replace country_id = 95 if country=="Sierra Leone"
replace country_id = 200 if country=="Singapore"
replace country_id = 201 if country=="Slovakia"
replace country_id = 202 if country=="Slovenia"
replace country_id = 130 if country=="Somalia"
replace country_id = 8 if country=="South Africa"
replace country_id = 96 if country=="Spain"
replace country_id = 131 if country=="Sri Lanka"
replace country_id = 33 if country=="Sudan"
replace country_id = 4 if country=="Suriname"
replace country_id = 132 if country=="Swaziland"
replace country_id = 5 if country=="Sweden"
replace country_id = 6 if country=="Switzerland"
replace country_id = 97 if country=="Syria"
replace country_id = 48 if country=="Taiwan"
replace country_id = 133 if country=="Tajikistan"
replace country_id = 47 if country=="Tanzania"
replace country_id = 49 if country=="Thailand"
replace country_id = 117 if country=="The Gambia"
replace country_id = 74 if country=="Timor Leste"
replace country_id = 134 if country=="Togo"
replace country_id = 135 if country=="Trinidad and Tobago"
replace country_id = 98 if country=="Tunisia"
replace country_id = 99 if country=="Turkey"
replace country_id = 136 if country=="Turkmenistan"
replace country_id = 50 if country=="Uganda"
replace country_id = 100 if country=="Ukraine"
replace country_id = 207 if country=="United Arab Emirates"
replace country_id = 101 if country=="United Kingdom"
replace country_id = 20 if country=="United States of America"
replace country_id = 102 if country=="Uruguay"
replace country_id = 140 if country=="Uzbekistan"
replace country_id = 206 if country=="Vanuatu"
replace country_id = 51 if country=="Venezuela"
replace country_id = 34 if country=="Vietnam"
replace country_id = 14 if country=="Yemen"
replace country_id = 61 if country=="Zambia"
replace country_id = 62 if country=="Zimbabwe"
replace country_id = 127 if country=="Namibia"
replace country_id = 117 if country=="Gambia"
replace country_id = 41 if country=="North Korea"
replace country_id = 42 if country=="South Korea"
replace country_id = 111 if country=="Congo, Dem. Rep."
replace country_id = 112 if country=="Congo, Rep."
replace country_id = 64 if country=="Ivory Coast"
replace country_id = 64 if country=="Cote d'Ivoire"
replace country_id = 13 if country=="Egypt, Arab Rep."
replace country_id = 117 if country=="Gambia, The"
replace country_id = 122 if country=="Kyrgyz Republic"
replace country_id = 123 if country=="Lao PDR"
replace country_id = 176 if country=="Macedonia, FYR"
replace country_id = 74 if country=="Timor-Leste"
replace country_id = 20 if country=="United States"
replace country_id = 20 if country=="USA"

save "Houle 2015 for merge.dta"


***************************************************
*************** Omoeva et al. 2018 ****************
***************************************************
use "Omoeva et al. EICC_dataset.dta" 

*** Group: "Ethnic/Religious"
keep if group ==1

*** Gender: "Both"
keep if gender ==1


generate country_id = .
order country_id, after(country)
replace country_id = 36 if country=="Afghanistan"
replace country_id = 12 if country=="Albania"
replace country_id = 103 if country=="Algeria"
replace country_id = 104 if country=="Angola"
replace country_id = 37 if country=="Argentina"
replace country_id = 105 if country=="Armenia"
replace country_id = 67 if country=="Australia"
replace country_id = 144 if country=="Austria"
replace country_id = 106 if country=="Azerbaijan"
replace country_id = 146 if country=="Bahrain"
replace country_id = 24 if country=="Bangladesh"
replace country_id = 147 if country=="Barbados"
replace country_id = 107 if country=="Belarus"
replace country_id = 148 if country=="Belgium"
replace country_id = 52 if country=="Benin"
replace country_id = 53 if country=="Bhutan"
replace country_id = 25 if country=="Bolivia"
replace country_id = 150 if country=="Bosnia and Herzegovina"
replace country_id = 68 if country=="Botswana"
replace country_id = 19 if country=="Brazil"
replace country_id = 152 if country=="Bulgaria"
replace country_id = 54 if country=="Burkina Faso"
replace country_id = 10 if country=="Myanmar"
replace country_id = 69 if country=="Burundi"
replace country_id = 55 if country=="Cambodia"
replace country_id = 108 if country=="Cameroon"
replace country_id = 66 if country=="Canada"
replace country_id = 70 if country=="Cape Verde"
replace country_id = 71 if country=="Central African Republic"
replace country_id = 109 if country=="Chad"
replace country_id = 72 if country=="Chile"
replace country_id = 110 if country=="China"
replace country_id = 15 if country=="Colombia"
replace country_id = 153 if country=="Comoros"
replace country_id = 112 if country=="Congo"
replace country_id = 111 if country=="Democratic Republic of the Congo"
replace country_id = 73 if country=="Costa Rica"
replace country_id = 154 if country=="Croatia"
replace country_id = 155 if country=="Cuba"
replace country_id = 156 if country=="Cyprus"
replace country_id = 157 if country=="Czech Republic"
replace country_id = 158 if country=="Denmark"
replace country_id = 113 if country=="Djibouti"
replace country_id = 114 if country=="Dominican Republic"
replace country_id = 75 if country=="Ecuador"
replace country_id = 13 if country=="Egypt"
replace country_id = 22 if country=="El Salvador"
replace country_id = 160 if country=="Equatorial Guinea"
replace country_id = 115 if country=="Eritrea"
replace country_id = 161 if country=="Estonia"
replace country_id = 38 if country=="Ethiopia"
replace country_id = 162 if country=="Fiji"
replace country_id = 163 if country=="Finland"
replace country_id = 76 if country=="France"
replace country_id = 116 if country=="Gabon"
replace country_id = 118 if country=="Georgia"
replace country_id = 77 if country=="Germany"
replace country_id = 7 if country=="Ghana"
replace country_id = 164 if country=="Greece"
replace country_id = 78 if country=="Guatemala"
replace country_id = 63 if country=="Guinea"
replace country_id = 119 if country=="Guinea-Bissau"
replace country_id = 166 if country=="Guyana"
replace country_id = 26 if country=="Haiti"
replace country_id = 27 if country=="Honduras"
replace country_id = 167 if country=="Hong Kong"
replace country_id = 210 if country=="Hungary"
replace country_id = 168 if country=="Iceland"
replace country_id = 39 if country=="India"
replace country_id = 56 if country=="Indonesia"
replace country_id = 79 if country=="Iran"
replace country_id = 80 if country=="Iraq"
replace country_id = 81 if country=="Ireland"
replace country_id = 169 if country=="Israel"
replace country_id = 82 if country=="Italy"
replace country_id = 64 if country=="Ivory Coast"
replace country_id = 120 if country=="Jamaica"
replace country_id = 9 if country=="Japan"
replace country_id = 83 if country=="Jordan"
replace country_id = 121 if country=="Kazakhstan"
replace country_id = 40 if country=="Kenya"
replace country_id = 43 if country=="Kosovo"
replace country_id = 171 if country=="Kuwait"
replace country_id = 122 if country=="Kyrgyzstan"
replace country_id = 123 if country=="Laos"
replace country_id = 84 if country=="Latvia"
replace country_id = 44 if country=="Lebanon"
replace country_id = 85 if country=="Lesotho"
replace country_id = 86 if country=="Liberia"
replace country_id = 124 if country=="Libya"
replace country_id = 173 if country=="Lithuania"
replace country_id = 174 if country=="Luxembourg"
replace country_id = 176 if country=="Macedonia"
replace country_id = 125 if country=="Madagascar"
replace country_id = 87 if country=="Malawi"
replace country_id = 177 if country=="Malaysia"
replace country_id = 88 if country=="Maldives"
replace country_id = 28 if country=="Mali"
replace country_id = 65 if country=="Mauretania"
replace country_id = 65 if country=="Mauritania"
replace country_id = 180 if country=="Mauritius"
replace country_id = 3 if country=="Mexico"
replace country_id = 126 if country=="Moldova"
replace country_id = 89 if country=="Mongolia"
replace country_id = 183 if country=="Montenegro"
replace country_id = 90 if country=="Morocco"
replace country_id = 57 if country=="Mozambique"
replace country_id = 127 if country=="Nambibia"
replace country_id = 58 if country=="Nepal"
replace country_id = 91 if country=="Netherlands"
replace country_id = 185 if country=="New Zealand"
replace country_id = 59 if country=="Nicaragua"
replace country_id = 60 if country=="Niger"
replace country_id = 45 if country=="Nigeria"
replace country_id = 186 if country=="Norway"
replace country_id = 187 if country=="Oman"
replace country_id = 29 if country=="Pakistan"
replace country_id = 92 if country=="Panama"
replace country_id = 93 if country=="Papua New Guinea"
replace country_id = 189 if country=="Paraguay"
replace country_id = 30 if country=="Peru"
replace country_id = 46 if country=="Philippines"
replace country_id = 17 if country=="Poland"
replace country_id = 21 if country=="Portugal"
replace country_id = 94 if country=="Qatar"
replace country_id = 190 if country=="Romania"
replace country_id = 11 if country=="Russia"
replace country_id = 129 if country=="Rwanda"
replace country_id = 196 if country=="Sao Tome and Principe"
replace country_id = 197 if country=="Saudi Arabia"
replace country_id = 31 if country=="Senegal"
replace country_id = 198 if country=="Serbia"
replace country_id = 199 if country=="Seychelles"
replace country_id = 95 if country=="Sierra Leone"
replace country_id = 200 if country=="Singapore"
replace country_id = 201 if country=="Slovakia"
replace country_id = 202 if country=="Slovenia"
replace country_id = 130 if country=="Somalia"
replace country_id = 8 if country=="South Africa"
replace country_id = 96 if country=="Spain"
replace country_id = 131 if country=="Sri Lanka"
replace country_id = 33 if country=="Sudan"
replace country_id = 4 if country=="Suriname"
replace country_id = 132 if country=="Swaziland"
replace country_id = 5 if country=="Sweden"
replace country_id = 6 if country=="Switzerland"
replace country_id = 97 if country=="Syria"
replace country_id = 48 if country=="Taiwan"
replace country_id = 133 if country=="Tajikistan"
replace country_id = 47 if country=="Tanzania"
replace country_id = 49 if country=="Thailand"
replace country_id = 117 if country=="The Gambia"
replace country_id = 74 if country=="Timor Leste"
replace country_id = 134 if country=="Togo"
replace country_id = 135 if country=="Trinidad and Tobago"
replace country_id = 98 if country=="Tunisia"
replace country_id = 99 if country=="Turkey"
replace country_id = 136 if country=="Turkmenistan"
replace country_id = 50 if country=="Uganda"
replace country_id = 100 if country=="Ukraine"
replace country_id = 207 if country=="United Arab Emirates"
replace country_id = 101 if country=="United Kingdom"
replace country_id = 20 if country=="United States of America"
replace country_id = 102 if country=="Uruguay"
replace country_id = 140 if country=="Uzbekistan"
replace country_id = 206 if country=="Vanuatu"
replace country_id = 51 if country=="Venezuela"
replace country_id = 34 if country=="Vietnam"
replace country_id = 14 if country=="Yemen"
replace country_id = 61 if country=="Zambia"
replace country_id = 62 if country=="Zimbabwe"
replace country_id = 127 if country=="Namibia"
replace country_id = 117 if country=="Gambia"
replace country_id = 41 if country=="North Korea"
replace country_id = 42 if country=="South Korea"
replace country_id = 111 if country=="Congo, Dem. Rep."
replace country_id = 112 if country=="Congo, Rep."
replace country_id = 64 if country=="Ivory Coast"
replace country_id = 64 if country=="Cote d'Ivoire"
replace country_id = 13 if country=="Egypt, Arab Rep."
replace country_id = 117 if country=="Gambia, The"
replace country_id = 122 if country=="Kyrgyz Republic"
replace country_id = 123 if country=="Lao PDR"
replace country_id = 176 if country=="Macedonia, FYR"
replace country_id = 74 if country=="Timor-Leste"
replace country_id = 20 if country=="United States"

save "Omoeva et al. for merge.dta"


***************************************************
************  Cederman et al. 2013 ****************
***************************************************
use "Cederman et al. 2013. repdata_ch7.dta" 


rename countryname country
generate country_id = .
order country_id, after(country)
replace country_id = 36 if country=="Afghanistan"
replace country_id = 12 if country=="Albania"
replace country_id = 103 if country=="Algeria"
replace country_id = 104 if country=="Angola"
replace country_id = 37 if country=="Argentina"
replace country_id = 105 if country=="Armenia"
replace country_id = 67 if country=="Australia"
replace country_id = 144 if country=="Austria"
replace country_id = 106 if country=="Azerbaijan"
replace country_id = 146 if country=="Bahrain"
replace country_id = 24 if country=="Bangladesh"
replace country_id = 147 if country=="Barbados"
replace country_id = 107 if country=="Belarus"
replace country_id = 148 if country=="Belgium"
replace country_id = 52 if country=="Benin"
replace country_id = 53 if country=="Bhutan"
replace country_id = 25 if country=="Bolivia"
replace country_id = 150 if country=="Bosnia and Herzegovina"
replace country_id = 68 if country=="Botswana"
replace country_id = 19 if country=="Brazil"
replace country_id = 152 if country=="Bulgaria"
replace country_id = 54 if country=="Burkina Faso"
replace country_id = 10 if country=="Myanmar"
replace country_id = 69 if country=="Burundi"
replace country_id = 55 if country=="Cambodia"
replace country_id = 108 if country=="Cameroon"
replace country_id = 66 if country=="Canada"
replace country_id = 70 if country=="Cape Verde"
replace country_id = 71 if country=="Central African Republic"
replace country_id = 71 if country=="CAR"
replace country_id = 109 if country=="Chad"
replace country_id = 72 if country=="Chile"
replace country_id = 110 if country=="China"
replace country_id = 15 if country=="Colombia"
replace country_id = 153 if country=="Comoros"
replace country_id = 112 if country=="Congo"
replace country_id = 111 if country=="Democratic Republic of the Congo"
replace country_id = 73 if country=="Costa Rica"
replace country_id = 154 if country=="Croatia"
replace country_id = 155 if country=="Cuba"
replace country_id = 156 if country=="Cyprus"
replace country_id = 157 if country=="Czech Republic"
replace country_id = 157 if country=="Czechoslovakia"
replace country_id = 158 if country=="Denmark"
replace country_id = 113 if country=="Djibouti"
replace country_id = 114 if country=="Dominican Republic"
replace country_id = 75 if country=="Ecuador"
replace country_id = 13 if country=="Egypt"
replace country_id = 22 if country=="El Salvador"
replace country_id = 160 if country=="Equatorial Guinea"
replace country_id = 115 if country=="Eritrea"
replace country_id = 161 if country=="Estonia"
replace country_id = 38 if country=="Ethiopia"
replace country_id = 162 if country=="Fiji"
replace country_id = 163 if country=="Finland"
replace country_id = 76 if country=="France"
replace country_id = 116 if country=="Gabon"
replace country_id = 118 if country=="Georgia"
replace country_id = 77 if country=="Germany"
replace country_id = 77 if country=="German Federal Republic"
replace country_id = 137 if country=="German Democratic Republic"
replace country_id = 7 if country=="Ghana"
replace country_id = 164 if country=="Greece"
replace country_id = 78 if country=="Guatemala"
replace country_id = 63 if country=="Guinea"
replace country_id = 119 if country=="Guinea-Bissau"
replace country_id = 166 if country=="Guyana"
replace country_id = 26 if country=="Haiti"
replace country_id = 27 if country=="Honduras"
replace country_id = 167 if country=="Hong Kong"
replace country_id = 210 if country=="Hungary"
replace country_id = 168 if country=="Iceland"
replace country_id = 39 if country=="India"
replace country_id = 56 if country=="Indonesia"
replace country_id = 79 if country=="Iran"
replace country_id = 80 if country=="Iraq"
replace country_id = 81 if country=="Ireland"
replace country_id = 169 if country=="Israel"
replace country_id = 82 if country=="Italy"
replace country_id = 64 if country=="Ivory Coast"
replace country_id = 120 if country=="Jamaica"
replace country_id = 9 if country=="Japan"
replace country_id = 83 if country=="Jordan"
replace country_id = 121 if country=="Kazakhstan"
replace country_id = 40 if country=="Kenya"
replace country_id = 43 if country=="Kosovo"
replace country_id = 171 if country=="Kuwait"
replace country_id = 122 if country=="Kyrgyzstan"
replace country_id = 123 if country=="Laos"
replace country_id = 84 if country=="Latvia"
replace country_id = 44 if country=="Lebanon"
replace country_id = 85 if country=="Lesotho"
replace country_id = 86 if country=="Liberia"
replace country_id = 124 if country=="Libya"
replace country_id = 173 if country=="Lithuania"
replace country_id = 174 if country=="Luxembourg"
replace country_id = 176 if country=="Macedonia"
replace country_id = 125 if country=="Madagascar"
replace country_id = 87 if country=="Malawi"
replace country_id = 177 if country=="Malaysia"
replace country_id = 88 if country=="Maldives"
replace country_id = 28 if country=="Mali"
replace country_id = 65 if country=="Mauretania"
replace country_id = 65 if country=="Mauritania"
replace country_id = 180 if country=="Mauritius"
replace country_id = 3 if country=="Mexico"
replace country_id = 126 if country=="Moldova"
replace country_id = 89 if country=="Mongolia"
replace country_id = 183 if country=="Montenegro"
replace country_id = 90 if country=="Morocco"
replace country_id = 57 if country=="Mozambique"
replace country_id = 127 if country=="Nambibia"
replace country_id = 58 if country=="Nepal"
replace country_id = 91 if country=="Netherlands"
replace country_id = 185 if country=="New Zealand"
replace country_id = 59 if country=="Nicaragua"
replace country_id = 60 if country=="Niger"
replace country_id = 45 if country=="Nigeria"
replace country_id = 186 if country=="Norway"
replace country_id = 187 if country=="Oman"
replace country_id = 29 if country=="Pakistan"
replace country_id = 92 if country=="Panama"
replace country_id = 93 if country=="Papua New Guinea"
replace country_id = 189 if country=="Paraguay"
replace country_id = 30 if country=="Peru"
replace country_id = 46 if country=="Philippines"
replace country_id = 17 if country=="Poland"
replace country_id = 21 if country=="Portugal"
replace country_id = 94 if country=="Qatar"
replace country_id = 190 if country=="Romania"
replace country_id = 11 if country=="Russia"
replace country_id = 129 if country=="Rwanda"
replace country_id = 196 if country=="Sao Tome and Principe"
replace country_id = 197 if country=="Saudi Arabia"
replace country_id = 31 if country=="Senegal"
replace country_id = 198 if country=="Serbia"
replace country_id = 198 if country=="Yugoslavia"
replace country_id = 199 if country=="Seychelles"
replace country_id = 95 if country=="Sierra Leone"
replace country_id = 200 if country=="Singapore"
replace country_id = 201 if country=="Slovakia"
replace country_id = 202 if country=="Slovenia"
replace country_id = 130 if country=="Somalia"
replace country_id = 8 if country=="South Africa"
replace country_id = 96 if country=="Spain"
replace country_id = 131 if country=="Sri Lanka"
replace country_id = 33 if country=="Sudan"
replace country_id = 4 if country=="Suriname"
replace country_id = 132 if country=="Swaziland"
replace country_id = 5 if country=="Sweden"
replace country_id = 6 if country=="Switzerland"
replace country_id = 97 if country=="Syria"
replace country_id = 48 if country=="Taiwan"
replace country_id = 133 if country=="Tajikistan"
replace country_id = 47 if country=="Tanzania"
replace country_id = 49 if country=="Thailand"
replace country_id = 117 if country=="The Gambia"
replace country_id = 74 if country=="Timor Leste"
replace country_id = 134 if country=="Togo"
replace country_id = 135 if country=="Trinidad and Tobago"
replace country_id = 98 if country=="Tunisia"
replace country_id = 99 if country=="Turkey"
replace country_id = 136 if country=="Turkmenistan"
replace country_id = 50 if country=="Uganda"
replace country_id = 100 if country=="Ukraine"
replace country_id = 207 if country=="United Arab Emirates"
replace country_id = 101 if country=="United Kingdom"
replace country_id = 20 if country=="United States of America"
replace country_id = 102 if country=="Uruguay"
replace country_id = 140 if country=="Uzbekistan"
replace country_id = 206 if country=="Vanuatu"
replace country_id = 51 if country=="Venezuela"
replace country_id = 34 if country=="Vietnam"
replace country_id = 35 if country=="Republic of Vietnam"
replace country_id = 14 if country=="Yemen"
replace country_id = 14 if country=="Yemen Arab Republic"
replace country_id = 23 if country=="Yemen People's Republic"
replace country_id = 61 if country=="Zambia"
replace country_id = 62 if country=="Zimbabwe"
replace country_id = 127 if country=="Namibia"
replace country_id = 117 if country=="Gambia"
replace country_id = 41 if country=="North Korea"
replace country_id = 42 if country=="South Korea"
replace country_id = 111 if country=="Congo, Dem. Rep."
replace country_id = 112 if country=="Congo, Rep."
replace country_id = 64 if country=="Ivory Coast"
replace country_id = 64 if country=="Cote d'Ivoire"
replace country_id = 13 if country=="Egypt, Arab Rep."
replace country_id = 117 if country=="Gambia, The"
replace country_id = 122 if country=="Kyrgyz Republic"
replace country_id = 123 if country=="Lao PDR"
replace country_id = 176 if country=="Macedonia, FYR"
replace country_id = 74 if country=="East Timor"
replace country_id = 20 if country=="United States"
replace country_id = 20 if country=="USA"

save "Cederman et al. 2013 for merge.dta"



***************************************************
************  Cederman et al. 2015 ****************
***************************************************
use "Cederman et al. (2015). jpr_triangulation_repdata.dta" 

///Cederman et al 2013: "Horizontal economic inequality (H7.2) is captured by the difference between the national average per capita income level and the per capita income of the poorest ethnic group in the country. More specifically, we define max low ratio as the relative income gap between the poorest group and the national average. In other words, this indicator takes the largest value of the low_ratio indicator introduced in Chapter 5 for each country year.

/// Buhaug et al 2014: We thenidentified the richest and poorest group in each country, from which we constructed country-level inequality indicators that capture the relative gap between the mean national income and the income level for the poorest and richest group, respectively:10  NHI: Negative horizontal inequality = country-level GDP per capita/mean per capita income for poorest group. PHI: Positive horizontal inequality = mean per capitaincome for richest group/country-level GDP per capita."

*** Drop irrelevant variables
drop status_monopoly status_dominant excluded family_downgraded2 b b2 family_warhist c_incidence_flagl ln_rgdppc_lag ln_pop pys_family inc_spline1 inc_spline2 inc_spline3 urban nb_eth_incidence_flag nb_all_incidence_flag lamerica eeurop ssafrica nafrme asia overlap cncat pop500k lineq_nh lineq_nl


*** generate country-level data
egen CL_low1_overlap = max(low1_overlap), by(cowcode year)
egen CL_high1_overlap = max(high1_overlap), by(cowcode year)
drop isrelevant onset_do_flag onset_do_mlog_flag
egen CL_high1_huber = max(high1_huber), by(cowcode year)
egen CL_low1_huber = max(low1_huber), by(cowcode year)
egen CL_high1_5050 = max(high1_5050), by(cowcode year)
egen CL_low1_5050 = max(low1_5050), by(cowcode year)
egen CL_high1 = max(high1), by(cowcode year)
egen CL_low1 = max(low1), by(cowcode year)
egen CL_high2 = max(high2), by(cowcode year)
egen CL_low2 = max(low2), by(cowcode year)
egen CL_high3 = max(high3), by(cowcode year)
egen CL_low3 = max(low3), by(cowcode year)
egen CL_high1_nhnl = max(high1_nhnl), by(cowcode year)
egen CL_low1_nhnl = max(low1_nhnl), by(cowcode year)
egen CL_high1_area = max(high1_area), by(cowcode year)
egen CL_low1_area = max(low1_area), by(cowcode year)
egen CL_high1_spatial = max(high1_spatial ), by(cowcode year)
egen CL_low1_spatial = max( low1_spatial), by(cowcode year)
egen CL_high1_spatial_5050 = max(high1_spatial_5050 ), by(cowcode year)
egen CL_low1_spatial_5050 = max(low1_spatial_5050 ), by(cowcode year)
egen CL_high1_nh = max(high1_nh), by(cowcode year)
egen CL_low1_nh = max(low1_nh), by(cowcode year)
egen CL_high1_nl = max(high1_nl), by(cowcode year)
egen CL_low1_nl = max(low1_nl), by(cowcode year)

*** Labels
label variable CL_high1_overlap "High (overlap-weighted average spatial/surveys)"
label variable CL_low1_overlap "Low (overlap-weighted average spatial/surveys)"
label variable CL_high1_huber "High (surveys)"
label variable CL_low1_huber "Low (surveys)"
label variable CL_high1_5050 "High (average spatial/surveys)"
label variable CL_low1_5050 "Low (average spatial/surveys)"
label variable CL_high1 "High (surveys/nuanced spatial mix 1))"
label variable CL_low1 "Low(surveys/nuanced spatial mix 1)"
label variable CL_high2 "High (surveys/nuanced spatial mix 2)"
label variable CL_low2 "Low(surveys/nuanced spatial mix 2)"
label variable CL_high3 "High (surveys/nuanced spatial mix 3)"
label variable CL_low3 "Low(surveys/nuanced spatial mix 3)"
label variable CL_high1_nhnl "High (spatial only, nuanced mix)"
label variable CL_low1_nhnl "Low (spatial only, nuanced mix)"
label variable CL_high1_area "High (area-weighted average spatial/surveys)"
label variable CL_low1_area "Low (area-weighted average spatial/surveys)"
label variable CL_high1_spatial "High (nuanced mix)"
label variable CL_low1_spatial "low1_spatial"
label variable CL_high1_spatial_5050 "High (50/50 mix)"
label variable CL_low1_spatial_5050 "Low (50/50 mix)"
label variable CL_high1_nh "High (G-Econ)"
label variable CL_low1_nh "Low (G-Econ)"
label variable CL_high1_nl "High (nightlights)"
label variable CL_low1_nl "low1_nl"

*** Drop group-level
drop cowgroupid groupid group high1_huber low1_huber high1_5050 low1_5050 high1 low1 high2 low2 high3 low3 high1_nhnl low1_nhnl high1_area low1_area high1_overlap low1_overlap high1_spatial low1_spatial high1_spatial_5050 low1_spatial_5050 high1_nh low1_nh high1_nl low1_nl 

*** Only one time series per country
duplicates drop

*** V-Dem ID
generate country_id = .
order country_id, after(countryname)
replace country_id = 36 if countryname=="Afghanistan"
replace country_id = 12 if countryname=="Albania"
replace country_id = 103 if countryname=="Algeria"
replace country_id = 104 if countryname=="Angola"
replace country_id = 37 if countryname=="Argentina"
replace country_id = 105 if countryname=="Armenia"
replace country_id = 67 if countryname=="Australia"
replace country_id = 144 if countryname=="Austria"
replace country_id = 106 if countryname=="Azerbaijan"
replace country_id = 146 if countryname=="Bahrain"
replace country_id = 24 if countryname=="Bangladesh"
replace country_id = 147 if countryname=="Barbados"
replace country_id = 107 if countryname=="Belarus"
replace country_id = 148 if countryname=="Belgium"
replace country_id = 52 if countryname=="Benin"
replace country_id = 53 if countryname=="Bhutan"
replace country_id = 25 if countryname=="Bolivia"
replace country_id = 150 if countryname=="Bosnia and Herzegovina"
replace country_id = 68 if countryname=="Botswana"
replace country_id = 19 if countryname=="Brazil"
replace country_id = 152 if countryname=="Bulgaria"
replace country_id = 54 if countryname=="Burkina Faso"
replace country_id = 10 if countryname=="Myanmar"
replace country_id = 69 if countryname=="Burundi"
replace country_id = 55 if countryname=="Cambodia"
replace country_id = 108 if countryname=="Cameroon"
replace country_id = 66 if countryname=="Canada"
replace country_id = 70 if countryname=="Cape Verde"
replace country_id = 71 if countryname=="Central African Republic"
replace country_id = 109 if countryname=="Chad"
replace country_id = 72 if countryname=="Chile"
replace country_id = 110 if countryname=="China"
replace country_id = 15 if countryname=="Colombia"
replace country_id = 153 if countryname=="Comoros"
replace country_id = 112 if countryname=="Congo"
replace country_id = 111 if countryname=="Democratic Republic of the Congo"
replace country_id = 73 if countryname=="Costa Rica"
replace country_id = 154 if countryname=="Croatia"
replace country_id = 155 if countryname=="Cuba"
replace country_id = 156 if countryname=="Cyprus"
replace country_id = 157 if countryname=="Czech Republic"
replace country_id = 157 if countryname=="Czechoslovakia"
replace country_id = 158 if countryname=="Denmark"
replace country_id = 113 if countryname=="Djibouti"
replace country_id = 114 if countryname=="Dominican Republic"
replace country_id = 75 if countryname=="Ecuador"
replace country_id = 13 if countryname=="Egypt"
replace country_id = 22 if countryname=="El Salvador"
replace country_id = 160 if countryname=="Equatorial Guinea"
replace country_id = 115 if countryname=="Eritrea"
replace country_id = 161 if countryname=="Estonia"
replace country_id = 38 if countryname=="Ethiopia"
replace country_id = 162 if countryname=="Fiji"
replace country_id = 163 if countryname=="Finland"
replace country_id = 76 if countryname=="France"
replace country_id = 116 if countryname=="Gabon"
replace country_id = 118 if countryname=="Georgia"
replace country_id = 77 if countryname=="Germany"
replace country_id = 77 if countryname=="German Federal Republic"
replace country_id = 137 if countryname=="German Democratic Republic"
replace country_id = 7 if countryname=="Ghana"
replace country_id = 164 if countryname=="Greece"
replace country_id = 78 if countryname=="Guatemala"
replace country_id = 63 if countryname=="Guinea"
replace country_id = 119 if countryname=="Guinea-Bissau"
replace country_id = 166 if countryname=="Guyana"
replace country_id = 26 if countryname=="Haiti"
replace country_id = 27 if countryname=="Honduras"
replace country_id = 167 if countryname=="Hong Kong"
replace country_id = 210 if countryname=="Hungary"
replace country_id = 168 if countryname=="Iceland"
replace country_id = 39 if countryname=="India"
replace country_id = 56 if countryname=="Indonesia"
replace country_id = 79 if countryname=="Iran"
replace country_id = 80 if countryname=="Iraq"
replace country_id = 81 if countryname=="Ireland"
replace country_id = 169 if countryname=="Israel"
replace country_id = 82 if countryname=="Italy"
replace country_id = 64 if countryname=="Ivory Coast"
replace country_id = 120 if countryname=="Jamaica"
replace country_id = 9 if countryname=="Japan"
replace country_id = 83 if countryname=="Jordan"
replace country_id = 121 if countryname=="Kazakhstan"
replace country_id = 40 if countryname=="Kenya"
replace country_id = 43 if countryname=="Kosovo"
replace country_id = 171 if countryname=="Kuwait"
replace country_id = 122 if countryname=="Kyrgyzstan"
replace country_id = 123 if countryname=="Laos"
replace country_id = 84 if countryname=="Latvia"
replace country_id = 44 if countryname=="Lebanon"
replace country_id = 85 if countryname=="Lesotho"
replace country_id = 86 if countryname=="Liberia"
replace country_id = 124 if countryname=="Libya"
replace country_id = 173 if countryname=="Lithuania"
replace country_id = 174 if countryname=="Luxembourg"
replace country_id = 176 if countryname=="Macedonia"
replace country_id = 125 if countryname=="Madagascar"
replace country_id = 87 if countryname=="Malawi"
replace country_id = 177 if countryname=="Malaysia"
replace country_id = 88 if countryname=="Maldives"
replace country_id = 28 if countryname=="Mali"
replace country_id = 65 if countryname=="Mauretania"
replace country_id = 65 if countryname=="Mauritania"
replace country_id = 180 if countryname=="Mauritius"
replace country_id = 3 if countryname=="Mexico"
replace country_id = 126 if countryname=="Moldova"
replace country_id = 89 if countryname=="Mongolia"
replace country_id = 183 if countryname=="Montenegro"
replace country_id = 90 if countryname=="Morocco"
replace country_id = 57 if countryname=="Mozambique"
replace country_id = 127 if countryname=="Nambibia"
replace country_id = 58 if countryname=="Nepal"
replace country_id = 91 if countryname=="Netherlands"
replace country_id = 185 if countryname=="New Zealand"
replace country_id = 59 if countryname=="Nicaragua"
replace country_id = 60 if countryname=="Niger"
replace country_id = 45 if countryname=="Nigeria"
replace country_id = 186 if countryname=="Norway"
replace country_id = 187 if countryname=="Oman"
replace country_id = 29 if countryname=="Pakistan"
replace country_id = 92 if countryname=="Panama"
replace country_id = 93 if countryname=="Papua New Guinea"
replace country_id = 189 if countryname=="Paraguay"
replace country_id = 30 if countryname=="Peru"
replace country_id = 46 if countryname=="Philippines"
replace country_id = 17 if countryname=="Poland"
replace country_id = 21 if countryname=="Portugal"
replace country_id = 94 if countryname=="Qatar"
replace country_id = 190 if countryname=="Romania"
replace country_id = 11 if countryname=="Russia"
replace country_id = 129 if countryname=="Rwanda"
replace country_id = 196 if countryname=="Sao Tome and Principe"
replace country_id = 197 if countryname=="Saudi Arabia"
replace country_id = 31 if countryname=="Senegal"
replace country_id = 198 if countryname=="Serbia"
replace country_id = 198 if countryname=="Yugoslavia"
replace country_id = 199 if countryname=="Seychelles"
replace country_id = 95 if countryname=="Sierra Leone"
replace country_id = 200 if countryname=="Singapore"
replace country_id = 201 if countryname=="Slovakia"
replace country_id = 202 if countryname=="Slovenia"
replace country_id = 130 if countryname=="Somalia"
replace country_id = 8 if countryname=="South Africa"
replace country_id = 96 if countryname=="Spain"
replace country_id = 131 if countryname=="Sri Lanka"
replace country_id = 33 if countryname=="Sudan"
replace country_id = 4 if countryname=="Suriname"
replace country_id = 132 if countryname=="Swaziland"
replace country_id = 5 if countryname=="Sweden"
replace country_id = 6 if countryname=="Switzerland"
replace country_id = 97 if countryname=="Syria"
replace country_id = 48 if countryname=="Taiwan"
replace country_id = 133 if countryname=="Tajikistan"
replace country_id = 47 if countryname=="Tanzania"
replace country_id = 49 if countryname=="Thailand"
replace country_id = 117 if countryname=="The Gambia"
replace country_id = 74 if countryname=="East Timor"
replace country_id = 134 if countryname=="Togo"
replace country_id = 135 if countryname=="Trinidad and Tobago"
replace country_id = 98 if countryname=="Tunisia"
replace country_id = 99 if countryname=="Turkey"
replace country_id = 136 if countryname=="Turkmenistan"
replace country_id = 50 if countryname=="Uganda"
replace country_id = 100 if countryname=="Ukraine"
replace country_id = 207 if countryname=="United Arab Emirates"
replace country_id = 101 if countryname=="United Kingdom"
replace country_id = 20 if countryname=="United States of America"
replace country_id = 102 if countryname=="Uruguay"
replace country_id = 140 if countryname=="Uzbekistan"
replace country_id = 206 if countryname=="Vanuatu"
replace country_id = 51 if countryname=="Venezuela"
replace country_id = 34 if countryname=="Vietnam"
replace country_id = 35 if countryname=="Republic of Vietnam"
replace country_id = 14 if countryname=="Yemen"
replace country_id = 14 if countryname=="Yemen Arab Republic"
replace country_id = 23 if countryname=="Yemen People's Republic"
replace country_id = 61 if countryname=="Zambia"
replace country_id = 62 if countryname=="Zimbabwe"
replace country_id = 127 if countryname=="Namibia"
replace country_id = 117 if countryname=="Gambia"
replace country_id = 41 if countryname=="North Korea"
replace country_id = 42 if countryname=="South Korea"

*Duplicate values for Israel
drop if country_id==. & cowcode==666

save "Cederman et al. 2015 for merge.dta"



***************************************************
************* Alesina et al. 2016 *****************
***************************************************
use "Alesina et al. 2016. EI_final_JPE.dta"


*** V-Dem ID
generate country_id = .
order country_id, after(country)
replace country_id = 36 if country=="Afghanistan"
replace country_id = 12 if country=="Albania"
replace country_id = 103 if country=="Algeria"
replace country_id = 104 if country=="Angola"
replace country_id = 37 if country=="Argentina"
replace country_id = 105 if country=="Armenia"
replace country_id = 67 if country=="Australia"
replace country_id = 144 if country=="Austria"
replace country_id = 106 if country=="Azerbaijan"
replace country_id = 146 if country=="Bahrain"
replace country_id = 24 if country=="Bangladesh"
replace country_id = 147 if country=="Barbados"
replace country_id = 107 if country=="Belarus"
replace country_id = 148 if country=="Belgium"
replace country_id = 52 if country=="Benin"
replace country_id = 53 if country=="Bhutan"
replace country_id = 25 if country=="Bolivia"
replace country_id = 150 if country=="Bosnia and Herzegovina"
replace country_id = 68 if country=="Botswana"
replace country_id = 19 if country=="Brazil"
replace country_id = 152 if country=="Bulgaria"
replace country_id = 54 if country=="Burkina Faso"
replace country_id = 10 if country=="Myanmar"
replace country_id = 69 if country=="Burundi"
replace country_id = 55 if country=="Cambodia"
replace country_id = 108 if country=="Cameroon"
replace country_id = 66 if country=="Canada"
replace country_id = 70 if country=="Cape Verde"
replace country_id = 71 if country=="Central African Republic"
replace country_id = 109 if country=="Chad"
replace country_id = 72 if country=="Chile"
replace country_id = 110 if country=="China"
replace country_id = 15 if country=="Colombia"
replace country_id = 153 if country=="Comoros"
replace country_id = 112 if country=="Congo, Rep."
replace country_id = 111 if country=="Congo, Dem. Rep."
replace country_id = 73 if country=="Costa Rica"
replace country_id = 154 if country=="Croatia"
replace country_id = 155 if country=="Cuba"
replace country_id = 156 if country=="Cyprus"
replace country_id = 157 if country=="Czech Republic"
replace country_id = 158 if country=="Denmark"
replace country_id = 113 if country=="Djibouti"
replace country_id = 114 if country=="Dominican Republic"
replace country_id = 75 if country=="Ecuador"
replace country_id = 13 if country=="Egypt, Arab Rep."
replace country_id = 22 if country=="El Salvador"
replace country_id = 160 if country=="Equatorial Guinea"
replace country_id = 115 if country=="Eritrea"
replace country_id = 161 if country=="Estonia"
replace country_id = 38 if country=="Ethiopia"
replace country_id = 162 if country=="Fiji"
replace country_id = 163 if country=="Finland"
replace country_id = 76 if country=="France"
replace country_id = 116 if country=="Gabon"
replace country_id = 118 if country=="Georgia"
replace country_id = 77 if country=="Germany"
replace country_id = 7 if country=="Ghana"
replace country_id = 164 if country=="Greece"
replace country_id = 78 if country=="Guatemala"
replace country_id = 63 if country=="Guinea"
replace country_id = 119 if country=="Guinea-Bissau"
replace country_id = 166 if country=="Guyana"
replace country_id = 166 if country=="Guyana (British Guiana)"
replace country_id = 26 if country=="Haiti"
replace country_id = 27 if country=="Honduras"
replace country_id = 167 if country=="Hong Kong"
replace country_id = 210 if country=="Hungary"
replace country_id = 168 if country=="Iceland"
replace country_id = 39 if country=="India"
replace country_id = 56 if country=="Indonesia"
replace country_id = 79 if country=="Iran, Islamic Rep."
replace country_id = 80 if country=="Iraq"
replace country_id = 81 if country=="Ireland"
replace country_id = 169 if country=="Israel"
replace country_id = 82 if country=="Italy"
replace country_id = 64 if pwtcountry=="Cote d`Ivoire"
replace country_id = 120 if country=="Jamaica"
replace country_id = 9 if country=="Japan"
replace country_id = 83 if country=="Jordan"
replace country_id = 121 if country=="Kazakhstan"
replace country_id = 40 if country=="Kenya"
replace country_id = 43 if country=="Kosovo"
replace country_id = 171 if country=="Kuwait"
replace country_id = 122 if country=="Kyrgyz Republic"
replace country_id = 123 if country=="Lao PDR"
replace country_id = 84 if country=="Latvia"
replace country_id = 44 if country=="Lebanon"
replace country_id = 85 if country=="Lesotho"
replace country_id = 86 if country=="Liberia"
replace country_id = 124 if country=="Libya"
replace country_id = 124 if country=="Libya (Tripolitania, Cyrenaica, Fezzan)"
replace country_id = 173 if country=="Lithuania"
replace country_id = 174 if country=="Luxembourg"
replace country_id = 176 if country=="Macedonia, FYR"
replace country_id = 125 if country=="Madagascar"
replace country_id = 87 if country=="Malawi"
replace country_id = 177 if country=="Malaysia"
replace country_id = 88 if country=="Maldives"
replace country_id = 28 if country=="Mali"
replace country_id = 65 if country=="Mauretania"
replace country_id = 65 if country=="Mauritania"
replace country_id = 180 if country=="Mauritius"
replace country_id = 3 if country=="Mexico"
replace country_id = 126 if country=="Moldova"
replace country_id = 89 if country=="Mongolia"
replace country_id = 183 if country=="Montenegro"
replace country_id = 90 if country=="Morocco"
replace country_id = 57 if country=="Mozambique"
replace country_id = 127 if country=="Nambibia"
replace country_id = 58 if country=="Nepal"
replace country_id = 91 if country=="Netherlands"
replace country_id = 185 if country=="New Zealand"
replace country_id = 59 if country=="Nicaragua"
replace country_id = 60 if country=="Niger"
replace country_id = 45 if country=="Nigeria"
replace country_id = 186 if country=="Norway"
replace country_id = 187 if country=="Oman"
replace country_id = 29 if country=="Pakistan"
replace country_id = 92 if country=="Panama"
replace country_id = 93 if country=="Papua New Guinea"
replace country_id = 189 if country=="Paraguay"
replace country_id = 30 if country=="Peru"
replace country_id = 46 if country=="Philippines"
replace country_id = 17 if country=="Poland"
replace country_id = 21 if country=="Portugal"
replace country_id = 94 if country=="Qatar"
replace country_id = 190 if country=="Romania"
replace country_id = 11 if country=="Russian Federation"
replace country_id = 129 if country=="Rwanda"
replace country_id = 196 if country=="Sao Tome and Principe"
replace country_id = 197 if country=="Saudi Arabia"
replace country_id = 31 if country=="Senegal"
replace country_id = 198 if country=="Serbia"
replace country_id = 198 if country=="Serbia and Montenegro"
replace country_id = 199 if country=="Seychelles"
replace country_id = 95 if country=="Sierra Leone"
replace country_id = 200 if country=="Singapore"
replace country_id = 201 if country=="Slovak Republic"
replace country_id = 202 if country=="Slovenia"
replace country_id = 130 if country=="Somalia"
replace country_id = 8 if country=="South Africa"
replace country_id = 96 if country=="Spain"
replace country_id = 131 if country=="Sri Lanka"
replace country_id = 33 if country=="Sudan"
replace country_id = 4 if country=="Suriname"
replace country_id = 132 if country=="Swaziland"
replace country_id = 5 if country=="Sweden"
replace country_id = 6 if country=="Switzerland"
replace country_id = 97 if country=="Syrian Arab Republic"
replace country_id = 48 if country=="Taiwan"
replace country_id = 133 if country=="Tajikistan"
replace country_id = 47 if country=="Tanzania"
replace country_id = 49 if country=="Thailand"
replace country_id = 117 if country=="Gambia, The"
replace country_id = 74 if country=="East Timor"
replace country_id = 74 if country=="Timor Leste"
replace country_id = 134 if country=="Togo"
replace country_id = 135 if country=="Trinidad and Tobago"
replace country_id = 98 if country=="Tunisia"
replace country_id = 99 if country=="Turkey"
replace country_id = 136 if country=="Turkmenistan"
replace country_id = 50 if country=="Uganda"
replace country_id = 100 if country=="Ukraine"
replace country_id = 207 if country=="United Arab Emirates"
replace country_id = 101 if country=="United Kingdom"
replace country_id = 20 if country=="United States"
replace country_id = 102 if country=="Uruguay"
replace country_id = 140 if country=="Uzbekistan"
replace country_id = 206 if country=="Vanuatu"
replace country_id = 51 if country=="Venezuela, RB"
replace country_id = 34 if country=="Vietnam"
replace country_id = 14 if country=="Yemen"
replace country_id = 61 if country=="Zambia"
replace country_id = 62 if country=="Zimbabwe"
replace country_id = 127 if country=="Namibia"
replace country_id = 117 if country=="Gambia"
replace country_id = 41 if country=="North Korea"
replace country_id = 42 if country=="Korea, Rep."
replace country_id = 203 if country=="Solomon Islands"
replace country_id = 236 if country=="Zanzibar"
replace country_id = 32 if country=="South Sudan"
replace country_id = 23 if country=="Yemen People's Republic"
replace country_id = 178 if country=="Malta"
replace country_id = 143 if country=="Antigua and Barbuda"
replace country_id = 145 if country=="Bahamas, The"
replace country_id = 149 if country=="Belize"
replace country_id = 151 if country=="Brunei Darussalam"
replace country_id = 159 if country=="Dominica"
replace country_id = 165 if country=="Grenada"
replace country_id = 192 if country=="St. Lucia"
replace country_id = 191 if country=="St. Kitts and Nevis"
replace country_id = 204 if country=="Tonga"
replace country_id = 193 if country=="St. Vincent and the Grenadines"
replace country_id = 194 if country=="Samoa"

* Reshape to long format
reshape long grg_a_lum ethg15_a_lum, i(country_id) j(year)

* Drop redundant variables
keep grg_a_lum12pc grg_a_lum00pc grg_a_lum92pc ethg15_a_lum12pc ethg15_a_lum00pc ethg15_a_lum92pc country_id year pwtcountry country code ccountry wbcountry wbcode isocode isonum name income region reg_eap reg_eca reg_mena reg_sa reg_we reg_na reg_ssa reg_lac landlock country7 country_isocode resolution admin_units pop_adminu urba_ext settlem_points areakm partitioned fractal logmort urb1500 pd1500 lndens1500 dens1500 lnpd1500 lwheatsugar giniadjnoc incshareadj colony_esp colony_gbr colony_fra colony_prt colony_oeu ln_pd1500 peuro lnland_area abslat lnabslat gi elf er ph lang_fragm rel_fragm altelf cdiv pol1 pol2 pol3 pol4 pol5 pol6 pol7 pol8 pol9 pol10 pol11 pol12 pol13 pol14 pol15 statehistn00v3 statehistn001v3 statehistn01v3 statehistn05v3 statehistn10v3 statehistn50v3 rgdppcch2000 lnrgdppcch2000 legor_uk legor_fr legor_so legor_ge legor_sc area_km2 code_wb  country_name rugged rugged_popw rugged_slope rugged_lsd rugged_pc land_area lat lon soil desert tropical dist_coast near_coast gemstones eth_fragm ef rq elf1 elf2 elf3 elf4 elf5 elf6 elf7 elf8 elf9 elf10 elf11 elf12 elf13 elf14 elf15 ethnicity_C2 language_C2 religion_C2 adiv adiv_sqr pdiv pdiv_sqr pdiv_aa pdiv_aa_sqr yst yst_aa yst1500 yst1500_scaled iso ountry distc eleva

label variable year "Year_old"

rename year year_old

recode year_old (92=1992) (0=2000) (12=2012), gen(year)

drop year_old

* Authors do not refer to 2006 observations in their article
drop if year ==6

order year, after(country_id)

sort country year, stable

replace ethg15_a_lum12pc = . if year==2000

replace ethg15_a_lum12pc = . if year==1992

replace ethg15_a_lum00pc = . if year==1992

replace ethg15_a_lum00pc = . if year==2012

replace ethg15_a_lum92pc = . if year==2000

replace ethg15_a_lum92pc = . if year==2012

replace grg_a_lum00pc = . if year==1992

replace grg_a_lum00pc = . if year==2012

replace grg_a_lum92pc = . if year==2012

replace grg_a_lum92pc = . if year==2000

replace grg_a_lum12pc = . if year==2000

replace grg_a_lum12pc = . if year==1992


clonevar ethg = ethg15_a_lum92pc
replace ethg = ethg15_a_lum00pc if year==2000
replace ethg = ethg15_a_lum12pc if year==2012

clonevar grg = grg_a_lum92pc
replace grg = grg_a_lum00pc if year==2000
replace grg = grg_a_lum12pc if year==2012

save "Alesina et al. 2016 for merge.dta"




***************************************
************ NAVCO 2.0 ****************
***************************************
use "NAVCO v2.0.dta"

g country = location
generate country_id = .
replace country_id = 36 if country=="Afghanistan"
replace country_id = 12 if country=="Albania"
replace country_id = 103 if country=="Algeria"
replace country_id = 104 if country=="Angola"
replace country_id = 37 if country=="Argentina"
replace country_id = 105 if country=="Armenia"
replace country_id = 67 if country=="Australia"
replace country_id = 144 if country=="Austria"
replace country_id = 106 if country=="Azerbaijan"
replace country_id = 146 if country=="Bahrain"
replace country_id = 24 if country=="Bangladesh"
replace country_id = 147 if country=="Barbados"
replace country_id = 107 if country=="Belarus"
replace country_id = 148 if country=="Belgium"
replace country_id = 52 if country=="Benin"
replace country_id = 53 if country=="Bhutan"
replace country_id = 25 if country=="Bolivia"
replace country_id = 150 if country=="Bosnia-Herzegovina"
replace country_id = 68 if country=="Botswana"
replace country_id = 19 if country=="Brazil"
replace country_id = 152 if country=="Bulgaria"
replace country_id = 54 if country=="Burkina Faso"
replace country_id = 10 if country=="Myanmar"
replace country_id = 10 if country=="Burma"
replace country_id = 69 if country=="Burundi"
replace country_id = 55 if country=="Cambodia"
replace country_id = 108 if country=="Cameroon"
replace country_id = 66 if country=="Canada"
replace country_id = 70 if country=="Cape Verde"
replace country_id = 71 if country=="Central African Republic"
replace country_id = 71 if country=="CAR"
replace country_id = 109 if country=="Chad"
replace country_id = 72 if country=="Chile"
replace country_id = 110 if country=="China"
replace country_id = 15 if country=="Colombia"
replace country_id = 153 if country=="Comoros"
replace country_id = 112 if country=="Congo"
replace country_id = 112 if country=="Congo-Brazzaville (ROC)"
replace country_id = 111 if country=="Democratic Republic of the Congo"
replace country_id = 73 if country=="Costa Rica"
replace country_id = 154 if country=="Croatia"
replace country_id = 155 if country=="Cuba"
replace country_id = 156 if country=="Cyprus"
replace country_id = 157 if country=="Czech Republic"
replace country_id = 157 if country=="Czechoslovakia"
replace country_id = 158 if country=="Denmark"
replace country_id = 113 if country=="Djibouti"
replace country_id = 114 if country=="Dominican Republic"
replace country_id = 75 if country=="Ecuador"
replace country_id = 13 if country=="Egypt"
replace country_id = 22 if country=="El Salvador"
replace country_id = 160 if country=="Equatorial Guinea"
replace country_id = 115 if country=="Eritrea"
replace country_id = 161 if country=="Estonia"
replace country_id = 38 if country=="Ethiopia"
replace country_id = 162 if country=="Fiji"
replace country_id = 163 if country=="Finland"
replace country_id = 76 if country=="France"
replace country_id = 116 if country=="Gabon"
replace country_id = 118 if country=="Georgia"
replace country_id = 77 if country=="German Federal Republic"
replace country_id = 77 if country=="Germany"
replace country_id = 137 if country=="German Democratic Republic"
replace country_id = 137 if country=="East Germany"
replace country_id = 7 if country=="Ghana"
replace country_id = 164 if country=="Greece"
replace country_id = 78 if country=="Guatemala"
replace country_id = 63 if country=="Guinea"
replace country_id = 119 if country=="Guinea-Bissau"
replace country_id = 119 if country=="Guinea-Biaasu"
replace country_id = 166 if country=="Guyana"
replace country_id = 26 if country=="Haiti"
replace country_id = 27 if country=="Honduras"
replace country_id = 167 if country=="Hong Kong"
replace country_id = 210 if country=="Hungary"
replace country_id = 168 if country=="Iceland"
replace country_id = 39 if country=="India"
replace country_id = 56 if country=="Indonesia"
replace country_id = 56 if country=="West Papua"
replace country_id = 79 if country=="Iran"
replace country_id = 80 if country=="Iraq"
replace country_id = 81 if country=="Ireland"
replace country_id = 169 if country=="Israel"
replace country_id = 82 if country=="Italy"
replace country_id = 64 if country=="Ivory Coast"
replace country_id = 120 if country=="Jamaica"
replace country_id = 9 if country=="Japan"
replace country_id = 83 if country=="Jordan"
replace country_id = 121 if country=="Kazakhstan"
replace country_id = 40 if country=="Kenya"
replace country_id = 43 if country=="Kosovo"
replace country_id = 171 if country=="Kuwait"
replace country_id = 122 if country=="Kyrgyzstan"
replace country_id = 123 if country=="Laos"
replace country_id = 84 if country=="Latvia"
replace country_id = 44 if country=="Lebanon"
replace country_id = 85 if country=="Lesotho"
replace country_id = 86 if country=="Liberia"
replace country_id = 124 if country=="Libya"
replace country_id = 173 if country=="Lithuania"
replace country_id = 174 if country=="Luxembourg"
replace country_id = 176 if country=="Macedonia"
replace country_id = 125 if country=="Madagascar"
replace country_id = 87 if country=="Malawi"
replace country_id = 177 if country=="Malaysia"
replace country_id = 88 if country=="Maldives"
replace country_id = 28 if country=="Mali"
replace country_id = 65 if country=="Mauretania"
replace country_id = 65 if country=="Mauritania"
replace country_id = 180 if country=="Mauritius"
replace country_id = 3 if country=="Mexico"
replace country_id = 126 if country=="Moldova"
replace country_id = 89 if country=="Mongolia"
replace country_id = 183 if country=="Montenegro"
replace country_id = 90 if country=="Morocco"
replace country_id = 57 if country=="Mozambique"
replace country_id = 127 if country=="Nambibia"
replace country_id = 58 if country=="Nepal"
replace country_id = 91 if country=="Netherlands"
replace country_id = 185 if country=="New Zealand"
replace country_id = 59 if country=="Nicaragua"
replace country_id = 60 if country=="Niger"
replace country_id = 45 if country=="Nigeria"
replace country_id = 186 if country=="Norway"
replace country_id = 187 if country=="Oman"
replace country_id = 29 if country=="Pakistan"
replace country_id = 92 if country=="Panama"
replace country_id = 93 if country=="Papua New Guinea"
replace country_id = 189 if country=="Paraguay"
replace country_id = 30 if country=="Peru"
replace country_id = 46 if country=="Philippines"
replace country_id = 17 if country=="Poland"
replace country_id = 21 if country=="Portugal"
replace country_id = 94 if country=="Qatar"
replace country_id = 190 if country=="Romania"
replace country_id = 11 if country=="Russia"
replace country_id = 11 if country=="USSR"
replace country_id = 129 if country=="Rwanda"
replace country_id = 196 if country=="Sao Tome and Principe"
replace country_id = 197 if country=="Saudi Arabia"
replace country_id = 31 if country=="Senegal"
replace country_id = 198 if country=="Serbia"
replace country_id = 198 if country=="Yugoslavia"
replace country_id = 199 if country=="Seychelles"
replace country_id = 95 if country=="Sierra Leone"
replace country_id = 200 if country=="Singapore"
replace country_id = 201 if country=="Slovakia"
replace country_id = 202 if country=="Slovenia"
replace country_id = 130 if country=="Somalia"
replace country_id = 8 if country=="South Africa"
replace country_id = 96 if country=="Spain"
replace country_id = 131 if country=="Sri Lanka"
replace country_id = 33 if country=="Sudan"
replace country_id = 32 if country=="South Sudan"
replace country_id = 4 if country=="Suriname"
replace country_id = 132 if country=="Swaziland"
replace country_id = 5 if country=="Sweden"
replace country_id = 6 if country=="Switzerland"
replace country_id = 97 if country=="Syria"
replace country_id = 48 if country=="Taiwan"
replace country_id = 133 if country=="Tajikistan"
replace country_id = 47 if country=="Tanzania"
replace country_id = 47 if country=="Tanzania/German East Africa"
replace country_id = 49 if country=="Thailand"
replace country_id = 117 if country=="The Gambia"
replace country_id = 74 if country=="Timor Leste"
replace country_id = 134 if country=="Togo"
replace country_id = 135 if country=="Trinidad and Tobago"
replace country_id = 98 if country=="Tunisia"
replace country_id = 99 if country=="Turkey"
replace country_id = 99 if country=="Ottoman Empire"
replace country_id = 136 if country=="Turkmenistan"
replace country_id = 50 if country=="Uganda"
replace country_id = 100 if country=="Ukraine"
replace country_id = 207 if country=="United Arab Emirates"
replace country_id = 101 if country=="United Kingdom"
replace country_id = 101 if country=="Northern Ireland"
replace country_id = 20 if country=="United States of America"
replace country_id = 102 if country=="Uruguay"
replace country_id = 140 if country=="Uzbekistan"
replace country_id = 206 if country=="Vanuatu"
replace country_id = 51 if country=="Venezuela"
replace country_id = 34 if country=="Democratic Republic of Vietnam"
replace country_id = 34 if country=="Vietnam"
replace country_id = 35 if country=="Republic of Vietnam"
replace country_id = 35 if country=="South Vietnam"
replace country_id = 14 if country=="Yemen"
replace country_id = 14 if country=="Yemen Arab Republic"
replace country_id = 14 if country=="Republic of Yemen"
replace country_id = 23 if country=="Yemen PDR"
replace country_id = 23 if country=="Yemen People's Republic"
replace country_id = 61 if country=="Zambia"
replace country_id = 62 if country=="Zimbabwe"
replace country_id = 127 if country=="Namibia"
replace country_id = 127 if country=="Namibia/South West Africa"
replace country_id = 117 if country=="Gambia"
replace country_id = 41 if country=="Democratic People's Republic of Korea"
replace country_id = 42 if country=="Republic of Korea"
replace country_id = 42 if country=="South Korea"
replace country_id = 111 if country=="Democratic Republic of Congo"
replace country_id = 111 if country=="Zaire/DRC"
replace country_id = 112 if country=="Republic of the Congo"
replace country_id = 64 if country=="Ivory Coast"
replace country_id = 64 if country=="Cote d'Ivoire"
replace country_id = 13 if country=="Egypt, Arab Rep."
replace country_id = 117 if country=="Gambia, The"
replace country_id = 122 if country=="Kyrgyz Republic"
replace country_id = 123 if country=="Lao PDR"
replace country_id = 176 if country=="Macedonia, FYR"
replace country_id = 74 if country=="East Timor"
replace country_id = 20 if country=="United States"
replace country_id = 20 if country=="USA"
replace country_id = 203 if country=="Solomon Islands"
replace country_id = 204 if country=="Tonga"
replace country_id = 151 if country=="Brunei"
replace country_id = 1081 if country=="Newfoundland"
replace country_id = 11384 if country=="Cape Colony"
replace country_id = 113818 if country=="Transvaal"
replace country_id = 113812 if country=="Natal"
replace country_id = 113814 if country=="Orange Free State"
replace country_id = 1145 if country=="Sahrawi"
replace country_id = 1145 if country=="Western Sahara"
replace country_id = 9999 if country=="Tibet"
replace country_id = 9998 if country=="Greenland"
* British Mandate
replace country_id = 209 if country=="Palestine" & year<=1948
replace country_id = 209 if country=="Palestinian Territories" & year<=1948
* West Bank
replace country_id = 128 if country=="Palestine" & year>=1948
replace country_id = 128 if country=="Palestinian Territories" & year>=1948


*** Nonviolent and violent campaigns dummy
gen nonvio_camp =1 if prim_method ==1
gen onset_nonvio_camp =1 if prim_method ==1 & cyear==0

gen vio_camp = 1 if prim_method ==0
gen onset_vio_camp =1 if prim_method ==0 & cyear==0

*** only include onsets
drop if cyear >=1

***
duplicates tag country_id year, g(tag)
sort country_id year

* Remove three country-year duplicates
drop in 98 if tag >0
drop in 182 if tag >0
drop in 245 if tag >0

drop tag


*** Fill panel gaps for included period and countries with "0"
tsset country_id year
tsfill, full
recode nonvio_camp onset_nonvio_camp vio_camp onset_vio_camp (.=0)

save "NAVCO 2.0 for merge.dta"


*********************************************************
*********************** SWIID 9.1 ***********************
*********************************************************

use "SWIID 9.1.dta" 

*** V-Dem ID
generate country_id = .
order country_id, after(country)
replace country_id = 36 if country=="Afghanistan"
replace country_id = 12 if country=="Albania"
replace country_id = 103 if country=="Algeria"
replace country_id = 104 if country=="Angola"
replace country_id = 37 if country=="Argentina"
replace country_id = 105 if country=="Armenia"
replace country_id = 67 if country=="Australia"
replace country_id = 144 if country=="Austria"
replace country_id = 106 if country=="Azerbaijan"
replace country_id = 146 if country=="Bahrain"
replace country_id = 24 if country=="Bangladesh"
replace country_id = 147 if country=="Barbados"
replace country_id = 107 if country=="Belarus"
replace country_id = 148 if country=="Belgium"
replace country_id = 52 if country=="Benin"
replace country_id = 53 if country=="Bhutan"
replace country_id = 25 if country=="Bolivia"
replace country_id = 150 if country=="Bosnia and Herzegovina"
replace country_id = 68 if country=="Botswana"
replace country_id = 19 if country=="Brazil"
replace country_id = 152 if country=="Bulgaria"
replace country_id = 54 if country=="Burkina Faso"
replace country_id = 10 if country=="Myanmar"
replace country_id = 69 if country=="Burundi"
replace country_id = 55 if country=="Cambodia"
replace country_id = 108 if country=="Cameroon"
replace country_id = 66 if country=="Canada"
replace country_id = 70 if country=="Cape Verde"
replace country_id = 71 if country=="Central African Republic"
replace country_id = 109 if country=="Chad"
replace country_id = 72 if country=="Chile"
replace country_id = 110 if country=="China"
replace country_id = 15 if country=="Colombia"
replace country_id = 153 if country=="Comoros"
replace country_id = 112 if country=="Congo-Brazzaville"
replace country_id = 111 if country=="Congo-Kinshasa"
replace country_id = 73 if country=="Costa Rica"
replace country_id = 154 if country=="Croatia"
replace country_id = 155 if country=="Cuba"
replace country_id = 156 if country=="Cyprus"
replace country_id = 157 if country=="Czech Republic"
replace country_id = 158 if country=="Denmark"
replace country_id = 113 if country=="Djibouti"
replace country_id = 114 if country=="Dominican Republic"
replace country_id = 75 if country=="Ecuador"
replace country_id = 13 if country=="Egypt"
replace country_id = 22 if country=="El Salvador"
replace country_id = 160 if country=="Equatorial Guinea"
replace country_id = 115 if country=="Eritrea"
replace country_id = 161 if country=="Estonia"
replace country_id = 38 if country=="Ethiopia"
replace country_id = 162 if country=="Fiji"
replace country_id = 163 if country=="Finland"
replace country_id = 76 if country=="France"
replace country_id = 116 if country=="Gabon"
replace country_id = 118 if country=="Georgia"
replace country_id = 77 if country=="Germany"
replace country_id = 7 if country=="Ghana"
replace country_id = 164 if country=="Greece"
replace country_id = 78 if country=="Guatemala"
replace country_id = 63 if country=="Guinea"
replace country_id = 119 if country=="Guinea-Bissau"
replace country_id = 166 if country=="Guyana"
replace country_id = 26 if country=="Haiti"
replace country_id = 27 if country=="Honduras"
replace country_id = 167 if country=="Hong Kong"
replace country_id = 210 if country=="Hungary"
replace country_id = 168 if country=="Iceland"
replace country_id = 39 if country=="India"
replace country_id = 56 if country=="Indonesia"
replace country_id = 79 if country=="Iran"
replace country_id = 80 if country=="Iraq"
replace country_id = 81 if country=="Ireland"
replace country_id = 169 if country=="Israel"
replace country_id = 82 if country=="Italy"
replace country_id = 64 if country=="CĂ´te d'Ivoire"
replace country_id = 120 if country=="Jamaica"
replace country_id = 9 if country=="Japan"
replace country_id = 83 if country=="Jordan"
replace country_id = 121 if country=="Kazakhstan"
replace country_id = 40 if country=="Kenya"
replace country_id = 43 if country=="Kosovo"
replace country_id = 171 if country=="Kuwait"
replace country_id = 122 if country=="Kyrgyzstan"
replace country_id = 123 if country=="Laos"
replace country_id = 84 if country=="Latvia"
replace country_id = 44 if country=="Lebanon"
replace country_id = 85 if country=="Lesotho"
replace country_id = 86 if country=="Liberia"
replace country_id = 124 if country=="Libya"
replace country_id = 173 if country=="Lithuania"
replace country_id = 174 if country=="Luxembourg"
replace country_id = 176 if country=="Macedonia"
replace country_id = 125 if country=="Madagascar"
replace country_id = 87 if country=="Malawi"
replace country_id = 177 if country=="Malaysia"
replace country_id = 88 if country=="Maldives"
replace country_id = 28 if country=="Mali"
replace country_id = 65 if country=="Mauretania"
replace country_id = 65 if country=="Mauritania"
replace country_id = 180 if country=="Mauritius"
replace country_id = 3 if country=="Mexico"
replace country_id = 126 if country=="Moldova"
replace country_id = 89 if country=="Mongolia"
replace country_id = 183 if country=="Montenegro"
replace country_id = 90 if country=="Morocco"
replace country_id = 57 if country=="Mozambique"
replace country_id = 127 if country=="Nambibia"
replace country_id = 58 if country=="Nepal"
replace country_id = 91 if country=="Netherlands"
replace country_id = 185 if country=="New Zealand"
replace country_id = 59 if country=="Nicaragua"
replace country_id = 60 if country=="Niger"
replace country_id = 45 if country=="Nigeria"
replace country_id = 186 if country=="Norway"
replace country_id = 187 if country=="Oman"
replace country_id = 29 if country=="Pakistan"
replace country_id = 92 if country=="Panama"
replace country_id = 93 if country=="Papua New Guinea"
replace country_id = 189 if country=="Paraguay"
replace country_id = 30 if country=="Peru"
replace country_id = 46 if country=="Philippines"
replace country_id = 17 if country=="Poland"
replace country_id = 21 if country=="Portugal"
replace country_id = 94 if country=="Qatar"
replace country_id = 190 if country=="Romania"
replace country_id = 11 if country=="Russia"
replace country_id = 129 if country=="Rwanda"
replace country_id = 196 if country=="SĂŁo TomĂŠ and PrĂ­ncipe"
replace country_id = 197 if country=="Saudi Arabia"
replace country_id = 31 if country=="Senegal"
replace country_id = 198 if country=="Serbia"
replace country_id = 199 if country=="Seychelles"
replace country_id = 95 if country=="Sierra Leone"
replace country_id = 200 if country=="Singapore"
replace country_id = 201 if country=="Slovakia"
replace country_id = 202 if country=="Slovenia"
replace country_id = 130 if country=="Somalia"
replace country_id = 8 if country=="South Africa"
replace country_id = 96 if country=="Spain"
replace country_id = 131 if country=="Sri Lanka"
replace country_id = 33 if country=="Sudan"
replace country_id = 4 if country=="Suriname"
replace country_id = 132 if country=="Swaziland"
replace country_id = 5 if country=="Sweden"
replace country_id = 6 if country=="Switzerland"
replace country_id = 97 if country=="Syria"
replace country_id = 48 if country=="Taiwan"
replace country_id = 133 if country=="Tajikistan"
replace country_id = 47 if country=="Tanzania"
replace country_id = 49 if country=="Thailand"
replace country_id = 117 if country=="The Gambia"
replace country_id = 74 if country=="Timor-Leste"
replace country_id = 134 if country=="Togo"
replace country_id = 135 if country=="Trinidad and Tobago"
replace country_id = 98 if country=="Tunisia"
replace country_id = 99 if country=="Turkey"
replace country_id = 136 if country=="Turkmenistan"
replace country_id = 50 if country=="Uganda"
replace country_id = 100 if country=="Ukraine"
replace country_id = 207 if country=="United Arab Emirates"
replace country_id = 101 if country=="United Kingdom"
replace country_id = 20 if country=="United States"
replace country_id = 102 if country=="Uruguay"
replace country_id = 140 if country=="Uzbekistan"
replace country_id = 206 if country=="Vanuatu"
replace country_id = 51 if country=="Venezuela"
replace country_id = 34 if country=="Vietnam"
replace country_id = 14 if country=="Yemen"
replace country_id = 61 if country=="Zambia"
replace country_id = 62 if country=="Zimbabwe"
replace country_id = 127 if country=="Namibia"
replace country_id = 117 if country=="Gambia"
replace country_id = 41 if country=="North Korea"
replace country_id = 42 if country=="South Korea"
replace country_id = 42 if country=="Korea"
replace country_id = 203 if country=="Solomon Islands"
replace country_id = 178 if country=="Malta"
replace country_id = 32 if country=="South Sudan"
replace country_id = 142 if country=="Andorra"
replace country_id = 143 if country=="Antigua and Barbuda"
replace country_id = 145  if country=="Bahamas"
replace country_id = 149 if country=="Belize"
replace country_id = 157 if country=="Czechoslovakia"
replace country_id = 159 if country=="Dominica"
replace country_id = 9998 if country=="Greenland"
replace country_id = 165 if country=="Grenada"
replace country_id = 170 if country=="Kiribati"
replace country_id = 181 if country=="Micronesia"
replace country_id = 188  if country=="Palau"
replace country_id = 194 if country=="Samoa"
replace country_id = 195 if country=="San Marino"
replace country_id = 191 if country=="St. Kitts and Nevis"
replace country_id = 192 if country=="St. Lucia"
replace country_id = 193 if country=="St. Vincent and Grenadines"
replace country_id = 204 if country=="Tonga"
replace country_id = 205 if country=="Tuvalu"
replace country_id = 198 if country=="Yugoslavia"
replace country_id = 151 if country=="Brunei"
replace country_id = 184 if country=="Nauru"
replace country_id = 11 if country=="Soviet Union"
*V-Dem distinguishes between West Bank / Gaza. West Bank has received the values.
replace country_id = 128 if country=="Palestinian Territories"

* No country ID's available
drop if country =="Puerto Rico"
drop if country =="Anguilla"
drop if country == "Turks and Caicos Islands"

* Search for duplicates
duplicates tag country_id year, g(tag)

* Overlap between Czech Republic & Czechoslovakia for 1988-89.
drop if country =="Czech Republic" & year <=1989

* Overlap between Russia and Soviet Union for 1988-1990
drop if country== "Russia" & year <=1990

drop tag

save "SWIID 9.1 for merge.dta"



***************************************************
*********************** BTI ***********************
***************************************************
use "BTI_2006-2022.dta"

generate country_id = .
replace country_id = 36 if country=="Afghanistan"
replace country_id = 12 if country=="Albania"
replace country_id = 103 if country=="Algeria"
replace country_id = 104 if country=="Angola"
replace country_id = 37 if country=="Argentina"
replace country_id = 105 if country=="Armenia"
replace country_id = 67 if country=="Australia"
replace country_id = 144 if country=="Austria"
replace country_id = 106 if country=="Azerbaijan"
replace country_id = 146 if country=="Bahrain"
replace country_id = 24 if country=="Bangladesh"
replace country_id = 147 if country=="Barbados"
replace country_id = 107 if country=="Belarus"
replace country_id = 148 if country=="Belgium"
replace country_id = 52 if country=="Benin"
replace country_id = 53 if country=="Bhutan"
replace country_id = 25 if country=="Bolivia"
replace country_id = 150 if country=="Bosnia and Herzegovina"
replace country_id = 68 if country=="Botswana"
replace country_id = 19 if country=="Brazil"
replace country_id = 152 if country=="Bulgaria"
replace country_id = 54 if country=="Burkina Faso"
replace country_id = 10 if country=="Myanmar"
replace country_id = 69 if country=="Burundi"
replace country_id = 55 if country=="Cambodia"
replace country_id = 108 if country=="Cameroon"
replace country_id = 66 if country=="Canada"
replace country_id = 70 if country=="Cape Verde"
replace country_id = 71 if country=="Central African Republic"
replace country_id = 71 if country=="CAR"
replace country_id = 109 if country=="Chad"
replace country_id = 72 if country=="Chile"
replace country_id = 110 if country=="China"
replace country_id = 15 if country=="Colombia"
replace country_id = 153 if country=="Comoros"
replace country_id = 112 if country=="Congo"
replace country_id = 111 if country=="Congo, DR"
replace country_id = 73 if country=="Costa Rica"
replace country_id = 154 if country=="Croatia"
replace country_id = 155 if country=="Cuba"
replace country_id = 156 if country=="Cyprus (-1974)"
replace country_id = 156 if country=="Cyprus (1975-)"
replace country_id = 157 if country=="Czech Republic"
replace country_id = 158 if country=="Denmark"
replace country_id = 113 if country=="Djibouti"
replace country_id = 114 if country=="Dominican Republic"
replace country_id = 75 if country=="Ecuador"
replace country_id = 13 if country=="Egypt"
replace country_id = 22 if country=="El Salvador"
replace country_id = 160 if country=="Equatorial Guinea"
replace country_id = 115 if country=="Eritrea"
replace country_id = 161 if country=="Estonia"
replace country_id = 38 if country=="Ethiopia"
replace country_id = 162 if country=="Fiji"
replace country_id = 163 if country=="Finland"
replace country_id = 76 if country=="France"
replace country_id = 76 if country=="France (-1962)"
replace country_id = 76 if country=="France (1963-)"
replace country_id = 116 if country=="Gabon"
replace country_id = 118 if country=="Georgia"
replace country_id = 77 if country=="Germany"
replace country_id = 77 if country=="Germany, West"
replace country_id = 7 if country=="Ghana"
replace country_id = 164 if country=="Greece"
replace country_id = 78 if country=="Guatemala"
replace country_id = 63 if country=="Guinea"
replace country_id = 119 if country=="Guinea-Bissau"
replace country_id = 166 if country=="Guyana"
replace country_id = 26 if country=="Haiti"
replace country_id = 27 if country=="Honduras"
replace country_id = 167 if country=="Hong Kong"
replace country_id = 210 if country=="Hungary"
replace country_id = 168 if country=="Iceland"
replace country_id = 39 if country=="India"
replace country_id = 56 if country=="Indonesia"
replace country_id = 79 if country=="Iran"
replace country_id = 80 if country=="Iraq"
replace country_id = 81 if country=="Ireland"
replace country_id = 169 if country=="Israel"
replace country_id = 82 if country=="Italy"
replace country_id = 64 if country=="Ivory Coast"
replace country_id = 120 if country=="Jamaica"
replace country_id = 9 if country=="Japan"
replace country_id = 83 if country=="Jordan"
replace country_id = 121 if country=="Kazakhstan"
replace country_id = 40 if country=="Kenya"
replace country_id = 43 if country=="Kosovo"
replace country_id = 171 if country=="Kuwait"
replace country_id = 122 if country=="Kyrgyzstan"
replace country_id = 123 if country=="Laos"
replace country_id = 84 if country=="Latvia"
replace country_id = 44 if country=="Lebanon"
replace country_id = 85 if country=="Lesotho"
replace country_id = 86 if country=="Liberia"
replace country_id = 124 if country=="Libya"
replace country_id = 173 if country=="Lithuania"
replace country_id = 174 if country=="Luxembourg"
replace country_id = 176 if country=="Macedonia"
replace country_id = 125 if country=="Madagascar"
replace country_id = 87 if country=="Malawi"
replace country_id = 177 if country=="Malaysia"
replace country_id = 177 if country=="Malaysia (-1965)"
replace country_id = 177 if country=="Malaysia (1966-)"
replace country_id = 88 if country=="Maldives"
replace country_id = 28 if country=="Mali"
replace country_id = 65 if country=="Mauretania"
replace country_id = 65 if country=="Mauritania"
replace country_id = 180 if country=="Mauritius"
replace country_id = 3 if country=="Mexico"
replace country_id = 126 if country=="Moldova"
replace country_id = 89 if country=="Mongolia"
replace country_id = 183 if country=="Montenegro"
replace country_id = 90 if country=="Morocco"
replace country_id = 57 if country=="Mozambique"
replace country_id = 127 if country=="Nambibia"
replace country_id = 58 if country=="Nepal"
replace country_id = 91 if country=="Netherlands"
replace country_id = 185 if country=="New Zealand"
replace country_id = 59 if country=="Nicaragua"
replace country_id = 60 if country=="Niger"
replace country_id = 45 if country=="Nigeria"
replace country_id = 186 if country=="Norway"
replace country_id = 187 if country=="Oman"
replace country_id = 29 if country=="Pakistan"
replace country_id = 29 if country=="Pakistan (-1970)"
replace country_id = 29 if country=="Pakistan (1971-)"
replace country_id = 92 if country=="Panama"
replace country_id = 93 if country=="Papua New Guinea"
replace country_id = 189 if country=="Paraguay"
replace country_id = 30 if country=="Peru"
replace country_id = 46 if country=="Philippines"
replace country_id = 17 if country=="Poland"
replace country_id = 21 if country=="Portugal"
replace country_id = 94 if country=="Qatar"
replace country_id = 190 if country=="Romania"
replace country_id = 11 if country=="Russia"
replace country_id = 11 if country=="USSR"
replace country_id = 129 if country=="Rwanda"
replace country_id = 196 if country=="Sao Tome and Principe"
replace country_id = 197 if country=="Saudi Arabia"
replace country_id = 31 if country=="Senegal"
replace country_id = 198 if country=="Serbia"
replace country_id = 198 if country=="Serbia and Montenegro"
replace country_id = 199 if country=="Seychelles"
replace country_id = 95 if country=="Sierra Leone"
replace country_id = 200 if country=="Singapore"
replace country_id = 201 if country=="Slovakia"
replace country_id = 202 if country=="Slovenia"
replace country_id = 130 if country=="Somalia"
replace country_id = 8 if country=="South Africa"
replace country_id = 96 if country=="Spain"
replace country_id = 131 if country=="Sri Lanka"
replace country_id = 33 if country=="Sudan"
replace country_id = 4 if country=="Suriname"
replace country_id = 132 if country=="Eswatini"
replace country_id = 5 if country=="Sweden"
replace country_id = 6 if country=="Switzerland"
replace country_id = 97 if country=="Syria"
replace country_id = 48 if country=="Taiwan"
replace country_id = 133 if country=="Tajikistan"
replace country_id = 47 if country=="Tanzania"
replace country_id = 49 if country=="Thailand"
replace country_id = 117 if country=="The Gambia"
replace country_id = 74 if country=="Timor Leste"
replace country_id = 134 if country=="Togo"
replace country_id = 135 if country=="Trinidad and Tobago"
replace country_id = 98 if country=="Tunisia"
replace country_id = 99 if country=="Turkey"
replace country_id = 136 if country=="Turkmenistan"
replace country_id = 50 if country=="Uganda"
replace country_id = 100 if country=="Ukraine"
replace country_id = 207 if country=="United Arab Emirates"
replace country_id = 101 if country=="United Kingdom"
replace country_id = 20 if country=="United States of America"
replace country_id = 102 if country=="Uruguay"
replace country_id = 140 if country=="Uzbekistan"
replace country_id = 206 if country=="Vanuatu"
replace country_id = 51 if country=="Venezuela"
replace country_id = 34 if country=="Vietnam"
replace country_id = 34 if country=="Vietnam, North"
replace country_id = 35 if country=="Vietnam, South"
replace country_id = 14 if country=="Yemen"
replace country_id = 14 if country=="Yemen, North"
replace country_id = 23 if country=="Yemen, South"
replace country_id = 61 if country=="Zambia"
replace country_id = 62 if country=="Zimbabwe"
replace country_id = 127 if country=="Namibia"
replace country_id = 117 if country=="Gambia"
replace country_id = 41 if country=="North Korea"
replace country_id = 42 if country=="South Korea"
replace country_id = 111 if country=="Congo, Democratic Republic"
replace country_id = 112 if country=="Congo, Rep."
replace country_id = 64 if country=="Ivory Coast"
replace country_id = 64 if country_code=="CIV"
replace country_id = 13 if country=="Egypt, Arab Rep."
replace country_id = 117 if country=="Gambia, The"
replace country_id = 122 if country=="Kyrgyz Republic"
replace country_id = 123 if country=="Lao PDR"
replace country_id = 176 if country=="North Macedonia"
replace country_id = 74 if country=="Timor-Leste"
replace country_id = 20 if country=="United States"
replace country_id = 20 if country=="USA"
replace country_id = 178 if country=="Malta"
replace country_id = 203 if country=="Solomon Islands"
replace country_id = 32 if country=="South Sudan"

* String
drop region

* Rename
rename admin basic_admin

save "BTI for merge.dta"


***************************************************
*********************** EPR ***********************
***************************************************

use "EPR_country.dta"  

label variable exclpop "exlcuded population"
label variable lexclpop "exlcuded population relative"
label variable discrimpop "discriminated population"
label variable ldiscrimpop "discrimpop relative"

*** Drop group-level
drop gwgroupid groupname isactive isrelevant groupsize statusid statusname regaut status_pwrrank status_monopoly status_dominant status_senior status_junior status_selfexclusion status_powerless status_discrim status_egip status_excl egip_groups_count excl_groups_count rlvt_groups_count actv_groups_count lpop lsize egippop legippop  rbal rlbal downgraded1 downgraded_excl1 downgraded_regaut1 upgraded1 upgraded_excl1 upgraded_regaut1 downgraded2 downgraded_excl2 downgraded_regaut2 upgraded2 upgraded_excl2 upgraded_regaut2 downgraded5 downgraded_excl5 downgraded_regaut5 upgraded5 upgraded_excl5 upgraded_regaut5 downgraded10 downgraded_excl10 downgraded_regaut10 upgraded10 upgraded_excl10 upgraded_regaut10 downgraded_hist downgraded_excl_hist downgraded_regaut_hist upgraded_hist upgraded_excl_hist upgraded_regaut_hist family_downgraded1 family_downgraded_excl1 family_downgraded_regaut1 family_upgraded1 family_upgraded_excl1 family_upgraded_regaut1 family_downgraded2 family_downgraded_excl2 family_downgraded_regaut2 family_upgraded2 family_upgraded_excl2 family_upgraded_regaut2 family_downgraded5 family_downgraded_excl5 family_downgraded_regaut5 family_upgraded5 family_upgraded_excl5 family_upgraded_regaut5 family_downgraded10 family_downgraded_excl10 family_downgraded_regaut10 family_upgraded10 family_upgraded_excl10 family_upgraded_regaut10 family_isrelevant active_anc_groupid active_des_groupid_arr relevant_anc_groupid relevant_des_groupid_arr ed_religion1 ed_rel1_size ed_religion2 ed_rel2_size ed_religion3 ed_rel3_size ed_language1 ed_lang1_size ed_language2 ed_lang2_size ed_language3 ed_lang3_size ed_phenotype1 ed_phenotype2 ed_phenotype3

*** Only one time series per country
duplicates drop


*** V-Dem ID
generate country_id = .
order country_id, after(countryname)
replace country_id = 36 if countryname=="Afghanistan"
replace country_id = 12 if countryname=="Albania"
replace country_id = 103 if countryname=="Algeria"
replace country_id = 104 if countryname=="Angola"
replace country_id = 37 if countryname=="Argentina"
replace country_id = 105 if countryname=="Armenia"
replace country_id = 67 if countryname=="Australia"
replace country_id = 144 if countryname=="Austria"
replace country_id = 106 if countryname=="Azerbaijan"
replace country_id = 145  if countryname=="Bahamas"
replace country_id = 146 if countryname=="Bahrain"
replace country_id = 24 if countryname=="Bangladesh"
replace country_id = 147 if countryname=="Barbados"
replace country_id = 107 if countryname=="Belarus"
replace country_id = 148 if countryname=="Belgium"
replace country_id = 149 if countryname=="Belize"
replace country_id = 52 if countryname=="Benin"
replace country_id = 53 if countryname=="Bhutan"
replace country_id = 25 if countryname=="Bolivia"
replace country_id = 150 if countryname=="Bosnia and Herzegovina"
replace country_id = 68 if countryname=="Botswana"
replace country_id = 19 if countryname=="Brazil"
replace country_id = 151 if countryname=="Brunei"
replace country_id = 152 if countryname=="Bulgaria"
replace country_id = 54 if countryname=="Burkina Faso"
replace country_id = 10 if countryname=="Myanmar"
replace country_id = 69 if countryname=="Burundi"
replace country_id = 55 if countryname=="Cambodia"
replace country_id = 108 if countryname=="Cameroon"
replace country_id = 66 if countryname=="Canada"
replace country_id = 70 if countryname=="Cape Verde"
replace country_id = 71 if countryname=="Central African Republic"
replace country_id = 109 if countryname=="Chad"
replace country_id = 72 if countryname=="Chile"
replace country_id = 110 if countryname=="China"
replace country_id = 15 if countryname=="Colombia"
replace country_id = 153 if countryname=="Comoros"
replace country_id = 112 if countryname=="Congo"
replace country_id = 111 if countryname=="Congo, DRC"
replace country_id = 73 if countryname=="Costa Rica"
replace country_id = 154 if countryname=="Croatia"
replace country_id = 155 if countryname=="Cuba"
replace country_id = 156 if countryname=="Cyprus"
replace country_id = 157 if countryname=="Czech Republic"
replace country_id = 157 if countryname=="Czechoslovakia"
replace country_id = 158 if countryname=="Denmark"
replace country_id = 113 if countryname=="Djibouti"
replace country_id = 114 if countryname=="Dominican Republic"
replace country_id = 75 if countryname=="Ecuador"
replace country_id = 13 if countryname=="Egypt"
replace country_id = 22 if countryname=="El Salvador"
replace country_id = 160 if countryname=="Equatorial Guinea"
replace country_id = 115 if countryname=="Eritrea"
replace country_id = 161 if countryname=="Estonia"
replace country_id = 38 if countryname=="Ethiopia"
replace country_id = 162 if countryname=="Fiji"
replace country_id = 163 if countryname=="Finland"
replace country_id = 76 if countryname=="France"
replace country_id = 116 if countryname=="Gabon"
replace country_id = 118 if countryname=="Georgia"
replace country_id = 77 if countryname=="Germany"
replace country_id = 137 if countryname=="Germany Democratic Republic"
replace country_id = 7 if countryname=="Ghana"
replace country_id = 164 if countryname=="Greece"
replace country_id = 78 if countryname=="Guatemala"
replace country_id = 63 if countryname=="Guinea"
replace country_id = 119 if countryname=="Guinea-Bissau"
replace country_id = 166 if countryname=="Guyana"
replace country_id = 166 if countryname=="Guyana (British Guiana)"
replace country_id = 26 if countryname=="Haiti"
replace country_id = 27 if countryname=="Honduras"
replace country_id = 167 if countryname=="Hong Kong"
replace country_id = 210 if countryname=="Hungary"
replace country_id = 168 if countryname=="Iceland"
replace country_id = 39 if countryname=="India"
replace country_id = 56 if countryname=="Indonesia"
replace country_id = 79 if countryname=="Iran"
replace country_id = 80 if countryname=="Iraq"
replace country_id = 81 if countryname=="Ireland"
replace country_id = 169 if countryname=="Israel"
replace country_id = 82 if countryname=="Italy"
replace country_id = 64 if countryname=="Ivory Coast"
replace country_id = 64 if countryname=="Cote d'Ivoire"
replace country_id = 120 if countryname=="Jamaica"
replace country_id = 9 if countryname=="Japan"
replace country_id = 83 if countryname=="Jordan"
replace country_id = 121 if countryname=="Kazakhstan"
replace country_id = 40 if countryname=="Kenya"
replace country_id = 43 if countryname=="Kosovo"
replace country_id = 171 if countryname=="Kuwait"
replace country_id = 122 if countryname=="Kyrgyzstan"
replace country_id = 123 if countryname=="Laos"
replace country_id = 84 if countryname=="Latvia"
replace country_id = 44 if countryname=="Lebanon"
replace country_id = 85 if countryname=="Lesotho"
replace country_id = 86 if countryname=="Liberia"
replace country_id = 124 if countryname=="Libya"
replace country_id = 124 if countryname=="Libya (Tripolitania, Cyrenaica, Fezzan)"
replace country_id = 173 if countryname=="Lithuania"
replace country_id = 174 if countryname=="Luxembourg"
replace country_id = 176 if countryname=="Macedonia"
replace country_id = 125 if countryname=="Madagascar"
replace country_id = 87 if countryname=="Malawi"
replace country_id = 177 if countryname=="Malaysia"
replace country_id = 88 if countryname=="Maldives"
replace country_id = 28 if countryname=="Mali"
replace country_id = 178 if countryname=="Malta"
replace country_id = 65 if countryname=="Mauretania"
replace country_id = 65 if countryname=="Mauritania"
replace country_id = 180 if countryname=="Mauritius"
replace country_id = 3 if countryname=="Mexico"
replace country_id = 126 if countryname=="Moldova"
replace country_id = 89 if countryname=="Mongolia"
replace country_id = 183 if countryname=="Montenegro"
replace country_id = 90 if countryname=="Morocco"
replace country_id = 57 if countryname=="Mozambique"
replace country_id = 127 if countryname=="Nambibia"
replace country_id = 58 if countryname=="Nepal"
replace country_id = 91 if countryname=="Netherlands"
replace country_id = 185 if countryname=="New Zealand"
replace country_id = 59 if countryname=="Nicaragua"
replace country_id = 60 if countryname=="Niger"
replace country_id = 45 if countryname=="Nigeria"
replace country_id = 186 if countryname=="Norway"
replace country_id = 187 if countryname=="Oman"
replace country_id = 29 if countryname=="Pakistan"
replace country_id = 92 if countryname=="Panama"
replace country_id = 93 if countryname=="Papua New Guinea"
replace country_id = 189 if countryname=="Paraguay"
replace country_id = 30 if countryname=="Peru"
replace country_id = 46 if countryname=="Philippines"
replace country_id = 17 if countryname=="Poland"
replace country_id = 21 if countryname=="Portugal"
replace country_id = 94 if countryname=="Qatar"
replace country_id = 190 if countryname=="Romania"
replace country_id = 11 if countryname=="Russia"
replace country_id = 129 if countryname=="Rwanda"
replace country_id = 196 if countryname=="Sao Tome and Principe"
replace country_id = 197 if countryname=="Saudi Arabia"
replace country_id = 31 if countryname=="Senegal"
replace country_id = 198 if countryname=="Serbia"
replace country_id = 198 if countryname=="Serbia and Montenegro"
replace country_id = 199 if countryname=="Seychelles"
replace country_id = 95 if countryname=="Sierra Leone"
replace country_id = 200 if countryname=="Singapore"
replace country_id = 201 if countryname=="Slovakia"
replace country_id = 202 if countryname=="Slovenia"
replace country_id = 130 if countryname=="Somalia"
replace country_id = 8 if countryname=="South Africa"
replace country_id = 96 if countryname=="Spain"
replace country_id = 131 if countryname=="Sri Lanka"
replace country_id = 33 if countryname=="Sudan"
replace country_id = 4 if countryname=="Suriname"
replace country_id = 132 if countryname=="Swaziland"
replace country_id = 5 if countryname=="Sweden"
replace country_id = 6 if countryname=="Switzerland"
replace country_id = 97 if countryname=="Syria"
replace country_id = 48 if countryname=="Taiwan"
replace country_id = 133 if countryname=="Tajikistan"
replace country_id = 47 if countryname=="Tanzania"
replace country_id = 49 if countryname=="Thailand"
replace country_id = 117 if countryname=="The Gambia"
replace country_id = 74 if countryname=="East Timor"
replace country_id = 74 if countryname=="Timor Leste"
replace country_id = 134 if countryname=="Togo"
replace country_id = 135 if countryname=="Trinidad and Tobago"
replace country_id = 98 if countryname=="Tunisia"
replace country_id = 99 if countryname=="Turkey"
replace country_id = 136 if countryname=="Turkmenistan"
replace country_id = 50 if countryname=="Uganda"
replace country_id = 100 if countryname=="Ukraine"
replace country_id = 207 if countryname=="United Arab Emirates"
replace country_id = 101 if countryname=="United Kingdom"
replace country_id = 20 if countryname=="United States"
replace country_id = 102 if countryname=="Uruguay"
replace country_id = 140 if countryname=="Uzbekistan"
replace country_id = 206 if countryname=="Vanuatu"
replace country_id = 51 if countryname=="Venezuela"
replace country_id = 34 if countryname=="Vietnam"
replace country_id = 35 if countryname=="Republic of Vietnam"
replace country_id = 14 if countryname=="Yemen"
replace country_id = 61 if countryname=="Zambia"
replace country_id = 62 if countryname=="Zimbabwe"
replace country_id = 127 if countryname=="Namibia"
replace country_id = 117 if countryname=="Gambia"
replace country_id = 41 if countryname=="North Korea"
replace country_id = 42 if countryname=="South Korea"
replace country_id = 41 if countryname=="Democratic People's Republic of Korea"
replace country_id = 42 if countryname=="Republic of Korea"
replace country_id = 203 if countryname=="Solomon Is."
replace country_id = 236 if countryname=="Zanzibar"
replace country_id = 32 if countryname=="South Sudan"
replace country_id = 23 if countryname=="Yemen People's Republic"
replace country_id = 9999 if countryname=="Tibet"

drop if countryname =="Serbia and Montenegro" & year ==2006

save "EPR 2020 for merge.dta"




**************************************************
******************* Merge ************************
**************************************************

*** Open Lexical 6.0 ****
use "Lexical Index v6.0 for merge.dta"

* Merge with V-Dem data
merge 1:1 country_id year using "V-Dem-CY-Full+Others-v11.1.dta"
rename _merge _merge_Vdem
tsset country_id year
tsfill, full

* Merge with Map data
merge 1:1 country_id year using "spmap_30_09_2021.dta"
xfill map_id, i(country_id)

* Merge with Fariss et al. GDP data
merge 1:1 country_id year using "Fariss et al. latent_gdp_pc with V-Dem_id for merge.dta", generate(_merge_Fariss_et_al)

* Merge with SWIID
merge 1:1 country_id year using "SWIID 9.1 for merge.dta", generate(_merge_SWIID)

* Merge with EPR country-level
merge 1:1 country_id year using "EPR 2020 for merge.dta", generate(_merge_EPR)

* Merge with BTI
merge 1:1 country_id year using "BTI for merge.dta", generate(_merge_BTI)

*** Merge with Houle 2015 country-level data
merge 1:1 country_id year using "Houle 2015 for merge.dta", generate(_merge_Houle_2015)

*** Merge with Alesina et al. (2016)
merge 1:1 country_id year using "Alesina et al. 2016 for merge.dta", generate(_merge_Alesina_et_al_2016)

*** Merge with Omoeva et al. (2018)
merge 1:1 country_id year using "Omoeva et al. for merge.dta", generate(_merge_Omoeva_et_al_2018)

*** Merge with Cederman et al. (2013)
merge 1:1 country_id year using "Cederman et al. 2013 for merge.dta", generate(_merge_Cederman_et_al_2013)

*** Merge with Cederman et al. (2015)
merge 1:1 country_id year using "Cederman et al. 2015 for merge.dta", generate(_merge_Cederman_et_al_2015)

*** Merge with NAVCO 2.0
merge 1:1 country_id year using "NAVCO 2.0 for merge.dta", generate(_merge_NAVCO) 


*** Keep only necessary variables ***
keep country_name country_id year map_id lexical_index transition_type breakdown_type e_boix_regime e_regionpol_6C v2peapssoc v2cagenmob v2cademmob v2clsocgrp v2cacamps v2caviol v2x_civlib v2exrescon v2x_jucon v2xlg_legcon v2caautmob v2regoppgroupsact_6 e_pt_coup grg nonvio_camp vio_camp camp_goals repression ggini NHIxl CL_low1_overlap eth_fragm rq cdiv ef latent_gdppc_mean_log e_migdpgro e_total_oil_income_pc v2svstterr gini_disp v2peapsecon identity equal conflict_intens cleavage lbgi1 lwgi1 exclpop discrimpop 


**** Save merged dataset ****
save "Main dataset.dta"

****
log close
translate log_merge.log log_merge.pdf